for RuBoard |
In general, there are two basic coding techniques you can use to implement the optimistic concurrency approach within ADO.NET. The default approach is to compare each column of data in the database (or other data provider data source) table to the original data values you read into your DataSet (cached copy) as part of your UPDATE statement ( WHERE clause). This will detect any optimistic concurrency violations. If any of the database data values have changed since you last read the data row, your UPDATE statement will fail (as you would probably want it to). At a minimum, this would force you to reread the data values from the database, see what they are, and see if you wanted to again update some data value further.
Another, quicker technique of doing the same thing is to utilize a timestamp column that may be available in the data table you are working with (as is available in MS SQL Server tables that have defined one). This technique allows you to read a timestamp value that is part of the database data row and then compare timestamps at the time you want to update the data back to the database. If the timestamp value has changed since the last time you read the data values, your UPDATE statement will fail (again, as you would want it to do).
for RuBoard |