开发者

SqlDataAdapter UpdateBatchSize row errors

The DataAdapter has a ContinueUpdateOnError property which you can set to 'True' which will continue processing the DataAdapter.Update command, even if an error is encountered. This is ideal, so I can catch errors at each row of data which fails to get inserted. However, this ONLY works properly if the batch processing is turned OFF (DataAdapter.UpdateBatchSize = 1).

If the DataAdapter.UpdateBatchSize is set to 0 or another number which would turn batch proces开发者_C百科sing on, and an error occurs within a record of the batch, then the whole batch fails the update. Obviously, this is not what I want to happen.

Ideally, I'd like to get a mix of the two scenarios. I'd like to be able to use batch processing, thereby having less round-trips to the database on insert of the rows, but at the same time I'd like to be able catch each individual row error as it occurs (which for some reason doesn't work when batch is turned on, and ContinueUpdateOnError is set to 'True'). To me, it looks like it has to be one way or another. I either Insert each row individually with a trip to the database for each insert, with the ability to catch each row error, or I try to send batches to the server, and if a row fails in the batch, then the whole batch fails.

Any thoughts?


From MSDN's page "DataAdapter.ContinueUpdateOnError Property":

If ContinueUpdateOnError is set to true, no exception is thrown when an error occurs during the update of a row. The update of the row is skipped and the error information is placed in the RowError property of the row in error. The DataAdapter continues to update subsequent rows.

And from MSDN's page "Performing Batch Operations Using DataAdapters (ADO.NET)":

Batch execution has the same effect as the execution of each individual statement. Statements are executed in the order that the statements were added to the batch. Errors are handled the same way in batch mode as they are when batch mode is disabled.

So either you've done something wrong or Microsoft's documentation on this isn't reliable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜