Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming / exceptions

Concurrency violation: the UpdateCommand affected 0 of the expected 1 records

3.00/5 (2 votes)
5 Dec 2009CPOL 41K  
hi all.i've just encountered a problem in C#:Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.that is an exception raised when there is a mismatch between the time that the DataTable reads from the DB until the time it wants to update it.one can use 2...
hi all.
i've just encountered a problem in C#:
"Concurrency violation: the UpdateCommand affected 0 of the expected 1 records".


that is an exception raised when there is a mismatch between the time that the DataTable reads from the DB until the time it wants to update it.

one can use 2 functions: dataAdapter.Fill(dataTable) and dataAdapter.Update(dataTable)

my problem was that i 1st made Fill(), then made changes to the table, than 2nd made Update(). until now it worked perfect. now when i want to make further Update() calls i get this Exception.

after some hours...i've figured out that all u need to do is use dataTable.Clear() and than call the Fill() method again and it works perfect!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)