Click here to Skip to main content
15,880,956 members
Articles / General Programming / Exceptions
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
4 Dec 2009CPOL 40K   3   3
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)


Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralAre you sure that this work? I'm using .NET4 and SQLite and ... Pin
real-insanity14-Dec-11 2:29
real-insanity14-Dec-11 2:29 
GeneralMeaning in that order.You Clear(),Fill() and Update() Pin
Member 81391345-Aug-11 4:46
Member 81391345-Aug-11 4:46 
Meaning in that order.You Clear(),Fill() and Update()
GeneralConcurrency violation case. Pin
Navneet Hegde7-Dec-09 1:59
Navneet Hegde7-Dec-09 1:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.