The DBConcurrencyException issue occurs when trying to use the Update() method on my Database. I have a table in a database that has an autoincremented ID column, and a DataTable in my c# program that gets its information from this table (including the auto increment part when i use MissingSchemaAction = MissingSchemaAction.AddWithKey).
If I create rows and add them to the datatable, the datatable automatically fills in the autoincremented ID column (starting where the database table left off) for me, which is fine. However if I delete the rows I just added (without first using Update() ) and add new ones, the datatable autoincrement column is filled with a value based on where the DATATABLE is, not where the database is, which is why I get the concurrency error.
for example:
The table in the database has these records:
1 Apple
2 Orange
3 Pear
Which gets copied to the datatable, so when I add a new row with the name value "grape" I get:
1 Apple
2 Orange
3 Pear
4 Grape
Which is fine, however if don't run the Update() method, and I delete the grape row and add a new row "Melon" I get:
1 Apple
2 Orange
3 Pear
5 Melon
And when I try to run Update(), the database is expecting 4 to be the next autoincremented value but instead is getting 5. So I get the error. The Update() occurs when the user clicks a "save" button, so ideally I'd like them to be able to make lots of changes as shown above before finally saving, but is the only way to preserve the concurrency to use Update() after each row is added/deleted?