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

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.
 
M

Marina

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top