문제

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?

도움이 되었습니까?

해결책

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
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top