12.9. Processing errors

The DataAdapter class throws generic exceptions when problems occur. To obtain a descriptive error message for each fault in a row and column in any table in a DataSet, we use the following technique.

  • Check the HasError property to see if any of the tables in the DataSet contain errors.

  • If no errors are detected in the DataSet, we can safely proceed with the Update.

  • If errors are detected in the DataSet, we use the GetErrors method to obtain the rows that contain the errors.

  • Once we have determined which rows contain the errors, we use the GetColumnError(DataColumn ) method to determine the incorrect columns for each row with errors.

The following example illustrates the technique described above:

 If (Not DS.HasErrors) ...

Get A Programmer's Guide to .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.