我使用try catch块使用ADO.NET2.0做批量更新,该的UpdateBatchSize设置500,我经常能捕捉异常,但我不知道哪一行更新失败,有没有办法让实际失效行?
Answer 1:
您可以使用事件RowUpdated让行的参考:
yourAdapter.RowUpdated += OnRowUpdated;
然后:
protected static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs args)
{
if (args.Status == UpdateStatus.ErrorsOccurred)
{
// Reference to row which throws error
var row = args.Row;
row.RowError = args.Errors.Message;
args.Status = UpdateStatus.SkipCurrentRow;
// Do something more
}
}
文章来源: How to track which row update failed in batch update