Concurrency handling ADO.Net

Fullstop 21 Reputation points
2021-03-06T16:51:38.61+00:00

Hi I have a winforms gridview that saves records on row by row basis. So basically, when end user changes data and leaves the respective row, changes are pushed to the DB. This works fine until multiple users work on the same row. Then the concurrency error is shown. At this point I need to display the changes to the user to choose which datarow wants to be taken as last. The one in DB, the one in gridview or the proposed one. Saving the chosen row is the problem. The gridview is marked with error, so update is not accepting the selected values. I must say, at this point I cannot refill the adapter since, large portion of data could be in grid and refiling it would be a performance killer. Can someone point me to a direction, with an example. Is there a way this to be done with the SqlDataAdapter.RowUpdating Event since I have strongly typed dataset in this project. Thanks N.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,835 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,395 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,277 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,036 Reputation points
    2021-03-06T17:12:23.803+00:00

    Hello,

    Since there are many ways to deal with databases e.g. TableAdapter or DataAdapter the following may or may not be the appropriate solution, even if not should provide proper direction. Also you might consider retry logic as explained here.

    0 comments No comments

  2. Duane Arnold 3,216 Reputation points
    2021-03-07T00:31:43.587+00:00

    Myself, I wouldn't be doing it with a datatable. I would be using ADO.NET, database command objects and inline T-SQL parameterized to persist a given row and doing optimistic locking of a given record on the table. I would force the user to reload the row in the grid with the latest record that was persisted to the database that had been changed. I wouldn't be giving any user a choice. It's either force the user to get the latest version of the record from the database and update it with their data or just abandon the update of the record, and that's their choices.

    0 comments No comments