AcceptChanges on new row (generate identity), cause future update

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm creating a new row in a DataTable, sending it to the server and the
CommandBuilder and DataAdapter calls the SqlServer and insert it properly
with a new ID generated. in the client side code looks like this :
....
newRow = myDS.Tables[0].NewRow;
....set new row's value...
newRow["id"] = m_Server.UpdateRows( myDS );
myDS.AcceptChanges();

later on i try to modify that same row and update it again
newRow["myStatus"] = "SendToCustomer";
m_Server.UpdateRows( myDS );

I've checked the status of the row before i call the server again, and it
says "modified" but the server yields "Concurrency violation: the
UpdateCommand affected 0 records"
why is that ?

many Thanks.
 
That would be because it lost the original values of the rows when you
called acceptchanges. The original value being used in the WHERE clause
comparison, is now the value of 'id' you set in your code. So the update
will always fail.
 
Back
Top