Last post Sep 07, 2018 08:49 AM by PatriceSc
Sep 07, 2018 03:51 AM|shsu|LINK
I am trying to delete the values in the table tblPersons
If username in the table tblPersons is having same username as that of newly inserted values and created date is before the current date(Not time)ie Inserting date. then the
old values must be deleted.Below code is working but some time all the values are deleted. Appreciate the help
cmd.Connection = co
"delete from tblPersons where exists (Select personId from tblPersons t2 where t2.UserName = tblPersons.UserName and CreatedDate < '" + ID.Text +
Sep 07, 2018 08:49 AM|PatriceSc|LINK
If inserted a bit before and depending how CreatedDate is defined I'm not surprised. Not directly related but using parameters is preferred over creating your own SQL string.
My personal preference is to use an identity value and delete all but the last id. It is also a bit surprising that you are even able to create a new row appparently for the same user.