title: How Do I Resolve Concurrency Violations with DataTables in .NET?
body: <p>I'm using DataTables in VB.NET 2.0, and I'm writing code to handle the concurrency violations I expect to occur in a multi-user environment. I understand how to trap concurrency violations, but I don't understand how to resolve them while using the DbCommandBuilder-generated INSERT, UPDATE, and DELETE commands.</p>
  
  <p>It seems to me that concurrency violations occur in five different situations:</p>
  
  <p>When...</p>
  
  <ol>
  <li>Updating a row that has been concurrently updated in the database</li>
  <li>Updating a row that has been concurrently deleted from the database</li>
  <li>Deleting a row that has been concurrently updated in the database</li>
  <li>Deleting a row that has been concurrently deleted from the database</li>
  <li>Inserting a row whose primary key has been concurrently inserted into the database</li>
  </ol>
  
  <p>I know how to resolve situation 1; I've found several examples of how to use the DataTable.Merge method to synchronize updated rows. However, Merge doesn't seem to work for the other 4 situations.</p>
  
  <p>As an example, suppose I'm trying to update a row that has been concurrently deleted from the database (situation 2), and my business rules tell me to restore the row into the database with the updated column values. I can't figure out how to change the DataRow properties so that the Adapter.Update method will insert the row into the database as required; Merge doesn't do it.</p>
  
  <p>Given the ease with which Merge handles situation 1, I'm certain there must be simple resolutions to the other concurrency violations as well, and I've just overlooked them. Can anyone provide me with a nudge in the right direction?</p>
  
  <p>-TC</p>