Change RowState to Added for existing record

I'm trying to set up my Winforms VB app to deal with multiuser operations (SQL Server for the database). One scenario to deal with is when a record is deleted by one user while another user is changing it; when the second user tries to save the changes, there is no record to update. This gives a DBConcurrencyException. Fine. There are two possible routes the second user may want to go at this point: 1) give up on the record (allow it to be deleted), or 2) restore the record using the data user #2 has in memory.

Option 1 is simple; toss the record from memory and go. Option 2 is proving surprisingly difficult to implement, because VB "knows" that the record is modified, not added, and therefore there ought to be a record in the database to match. It seems to me that if I reset the RowState to Added instead of Modified, I'll be ready, but RowState is a ReadOnly property, and I can't find a way to change it.

About the only thing I can think of is to create a new record and copy all of the items from the old record to the new record, then delete the old record and save the new. But that's pretty tedious (particularly since I have 10 child tables that will need the same treatment). Is there a simpler way?

Any other thoughts on traps to beware of for multiuser ops are welcome.
LVL 20
Who is Participating?
Mez4343Connect With a Mentor Commented:
Ok, so if the desired usability is that User1 can Add/Update/Delete row(s) and User2 and then re-add/re-update/delete the same row(s). maybe this will work for you.

You can loop through all rows and AcceptChanges() and then run a row.SetAdded()

Havent tried it but here is a a link.
Have you considered a locking strategy in SQL to prevent mutli-user edits on the same row? Option3

ElrondCTAuthor Commented:
As the page you link to notes, pessimistic concurrency (record locking) isn't a good option when users are interacting with data and potentially will be taking extended time to make the changes, which is my situation.
You would first need to deteremine if the row has been deleted by some other user prior to running the AcceptChages() and SetAdded() on the row to be readded.
ElrondCTAuthor Commented:
Excellent. This does exactly what I want. Thanks for mentioning the need to .AcceptChanges first, since .SetAdded won't work with a Modified row.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.