Concurrency violation: the UpdateCommand affected 0 of the expected 1 records
I know it's very late but maybe it will help someone.
Made the following changes to your code:
try
{
adapt.Update(dt);
Put these lines here and use your variable
Me.yourTableAdapter.Update(Me.yourDataSet.yourTable)
Me.yourDataSet.youTable.AcceptChanges()
Me.yourTableAdapter.Fill(Me.yourDataSet.yourTable)
it worked like a charm for me hope it will work for you.
}
catch (SqlException ex)
{
Debug.WriteLine(ex.Message);
}
I have been chasing this error in my application for weeks! I finally found my issue.
What I found in my application...
I have many textboxes
, comboboxes
, etc. bound with databindings. Some of these fields are being updated from combinations of other fields. This all works great with one exception
If one of the calculated fields gets re-calculated after you
EndEdit
and before youUpdate
, this will cause adbconcurrency
violation.
This error doesn't have to mean that the row doesn't exist any more; it simply means that it didn't update a row for some reason. My reason was that the data had three different states so it thought that someone else had changed the data before I called the Update.
BTW, this is a single MDF located on the users computer so no one else has access to it to change it during the Update. One user, One Update. My code was the "other" user.
Hope this can help point someone else in the right direction for their application.