[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Change RowState to Added for existing record

Posted on 2011-03-15
5
Medium Priority
?
394 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:ElrondCT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Mez4343
ID: 35140499
Have you considered a locking strategy in SQL to prevent mutli-user edits on the same row? Option3

http://msdn.microsoft.com/en-us/library/aa0416cz.aspx

0
 
LVL 20

Author Comment

by:ElrondCT
ID: 35141575
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.
0
 
LVL 10

Accepted Solution

by:
Mez4343 earned 2000 total points
ID: 35142083
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.
http://stackoverflow.com/questions/4582380/c-dataset-dataadapter-how-to-change-row-state-to-invoke-an-insert
0
 
LVL 10

Expert Comment

by:Mez4343
ID: 35142101
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.
0
 
LVL 20

Author Comment

by:ElrondCT
ID: 35143730
Excellent. This does exactly what I want. Thanks for mentioning the need to .AcceptChanges first, since .SetAdded won't work with a Modified row.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question