Click here to Skip to main content
15,064,140 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello

in this code:
C#
SqlConnection CON1 = new SqlConnection();
CON1.ConnectionString = DATAPROVIDER.DataProvider.ConnectionString;
CON1.Open();
SqlCommand b21 = new SqlCommand("select * from " + DetailTableName);
GridEXTable _table1 = ((GridEX)ChildControl).RootTable;
SqlDataAdapter sda1 = new SqlDataAdapter(b21.CommandText, CON1);
SqlCommandBuilder cmb1 = new SqlCommandBuilder(sda1);
cmb1.GetDeleteCommand();
sda1.Update(table);
CON1.Close();

I recieve this error:

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

Please help me.
Thanks
Posted
Updated 15-Aug-11 1:14am
v2

You're probably trying to update a row that doesn't exist.

If you google the error message, you'll get over 7700 results back.

This one [^] is pretty useful.
   
this occours when you're trying to update or delete a record that cannot be found, it could have been deleted or you're using concurrency.
   
As already said this is typically a situation where the adapter cannot find a row to update. However, in your code you call the update of the dataadapter for variable table. However in the code you posted, you don't seem to fill this table at all? Also you don't make any modifications to the table.

Are you referencing a correct variable or is something missing from the post?

As a side-note the GetDeleteCommand seems pointless since you don't put the returning object to any variable.
   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900