如何在对数据集进行填充之前检查数据库行值是否已更改

时间:2016-06-30 20:49:13

标签: ado.net dataset dataadapter optimistic-concurrency

当我尝试使用数据集中的某些修改值更新数据库时,如果在执行数据集上的填充方法后手动更改数据库中的某些值,则会发生并发异常。 (如果我手动删除一行,然后尝试调用数据适配器的方法更新,我只会得到异常。)

我应该如何查看是否有一个"脏读"在我的数据集上?。

1 个答案:

答案 0 :(得分:0)

You have several options.

  • Keeping a copy of the original entity set to compare against and make the is dirty determination at the point you need to know whether it's dirty.

  • Checking the datarow's rowstate property and if Modified compare the values in the Current and Original DataRowVersions. If the second change makes the value the same as the original then you could call RejectChanges, however that would reject all changes on the row. You will have to manually track each field since the dataset only keeps per-row or per-table changes.