Getting concurrency error on updating record with data adapter

前端 未结 2 876
生来不讨喜
生来不讨喜 2021-01-17 05:40

This is my table:

Student:StudentId int PK autoincrement,Name varchar(20)

When i am trying to update last added records then i

2条回答
  •  不思量自难忘°
    2021-01-17 05:49

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

提交回复
热议问题