如何跟踪在批量更新中失败的行更新 [英] How to track which row update failed in batch update

查看:224
本文介绍了如何跟踪在批量更新中失败的行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用try catch块使用ADO.NET2.0进行批处理更新,UpdateBatchSize设置为500,我经常可以捕获异常,但是我不知道哪个行更新失败,有没有办法以获得实际的失败行?

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?

推荐答案

您可以使用事件 RowUpdated 获取行的引用:

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

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

这篇关于如何跟踪在批量更新中失败的行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆