1

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

4

1 回答 1

2

您可以使用事件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
    }
}
于 2012-09-24T04:18:32.727 回答