Question Last record update problem

prasad kulkarni

Well-known member
Joined
Sep 7, 2009
Messages
62
Programming Experience
1-3
Hello,

I am using vb.net 2005 (window application). In my form1 there is two button
'Save' and 'Update' . when I fill information and save last record using da.update(ds,'tablename') then no problem . But when I Immediately update last record using da.update(ds,'tablename') ,
then I get error: 'Concurrency violation: the UpdateCommand affected 0 of the expected 1 records ' .
My table have a primary key. For database sql server 2000 is used .

if any one know the answer , please reply me soon.
 
I think:

You have a key column in your local datatable that is e.g. -1
You add a new row and send to the db, it gets an ID of e.g. 237
You didnt set the options to populate this back into the local row
The local row becomes RowState = Unchanged
You edit the row, it becomes RowState = Modified
You update again to ave to DB
ADO.net tries to run UPDATE command using -1 as the id, not 237 (because it never populated back)

0 out of 1 rows were updated = Concurrency violation


I'ts not concurrency in the sense that another user edited the same row. It's a case that the db couldnt find any row to update when Microsoft's code was expecting it to find one row and in this case, and optimistic concurrency is on, a ConcurrencyException is thrown. It's not concurrency that is the problem, but MS's code doesnt know that
 

Latest posts

Back
Top