As I’m working as a .NET developer at LoQutus, my .NET posts will grow increasingly, therefore, there is a new Category “.NET Development”. Read on for the first post! 🙂
When working with DataSets, I encountered a strange problem, taking me to a very dark place on the internet: Concurrency handling in ADO.NET.
The cause of the problem had little to do with any concurrency, so read on to find out whether it may solve your problem too!The problem is now clear to me: I had created new rows in a DataTable, using ImportRow(). I then modified some of their data.
When committing the data from this dataset to the database, I got the following exception:
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
This is actually rather unnatural. The ImportRow() method actually sets the RowState of the new row to “Unchanged” rather than “Added”.
So if you set every row’s RowState to “Added” – using the SetAdded() method of that row – the ghost concurrency problem is solved.
Hope anyone finds this useful 🙂