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

Advertisements

2 thoughts on “Concurrency violation: the UpdateCommand affected 0 of the expected 1 records

  1. You can also get the concurrency error if you have reordered the columns in your table and haven’t updated the order in the select clause of the tableadapter’s query.

    Like

Leave a Reply / Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s