How to: Handle Concurrency Errors
You can catch the DBConcurrencyException object to assist in resolving issues arising from concurrency violations. The DBConcurrencyException object returns the data row that caused the error. For more information, see DBConcurrencyException Members.
The following example attempts to update a data source with the contents of NorthwindDataSet from within a try/catch block, if an error is raised an error message along with the first column of the offending data row is displayed.
The code below is an illustration of one strategy in handling a database update error. The code assumes several things; an existing connection to a database, an existing dataset, as well as the assumption that execution of the update command will raise a concurrency violation. For more information and a complete example, see Walkthrough: Handling a Concurrency Exception.
To resolve a concurrency violation
Execute the command to update the database from within a try/catch block.
If an exception is raised, inspect the catch statement's Row property to determine what caused the violation.
Add code to resolve the error based on your application's business rules.
The following code uses a CustomersTableAdapter and NorthwindDataSet as examples of the adapter and dataset in your application.