This is my table:
Student:StudentId int PK autoincrement,Name varchar(20)
When i am trying to update last added records then i
When you do the first update, the row is written to the database and it gets a primary key per the AUTOINCREMENT
. However, the row inside the DataTable
does not reflect the changed ID. Therefore, when you try to do the second update, it can't find the row you're intending to update (the ID in the data table doesn't match the ID in the database). Consequently, you get a concurrency error.
That's why, in order to get the ID into the DataTable
, you will need to refresh the contents of the DataTable
before doing the second update.
To refresh the DataTable
, call:
adapter.Fill()
For more information, read Merging DataSet Contents.