How to track which row update failed in batch update

好久不见. 提交于 2020-01-05 05:45:10

问题


I'm using a try catch blocks to do a batch update using ADO.NET2.0, the UpdateBatchSize is set 500, I can often catch exceptions, but I don't know which row update failed, is there a way to get the actual failed row?


回答1:


You can use event RowUpdated to get the reference of row:

yourAdapter.RowUpdated += OnRowUpdated;

Then:

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
    }
}


来源:https://stackoverflow.com/questions/12558354/how-to-track-which-row-update-failed-in-batch-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!