Concurrency violation: the UpdateCommand affected 0 of the expected 1 records
{“Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.”}
Terrible exception.
Well what was happening is i had a datatable, and i was editing it.
At one of the points i update it, then I call in a different class’s method, pass only the unique key of one of the rows and make certain claculations, change the row, and update it.
Now when I go back to my original table, and update it….it threw this error.
Lets take this example.
The table “myTable” has the following fields: ID,name,address,country,credit
where ID is the primary key.
lets take a row ID=1,name=Shashi,address=Brisbane,country=Australia,credit = 20
i have 2 classes MyClass and MyCalcClass
MyClass is instantiated and it acquires a row from myTable lets call it myRow
now i instantiate an instance of MyCalcClass called objCalc and send it myRow.ID.
now objCalc changes the value of credit (lets say multiplies by 10) to 200 from 20 and saves it.
now back in MyClass if i save myRow.
The adapter throws back with the error…. why?
well….for ID=1 the credit value shud have originally been 20 but it dosent find it..and hence it throws a concurrency error
to overcome this…..either send the entire row so that the row is update while objCalc does its changes ,OR: repopulate myRow for that ID so that you have the latest updated version of the row.
Eureka, it worked for me
This was originally posted here.

Like
Report
*This post is locked for comments