Identifying Errors in the Table

The GetErrors( ) method returns an array of the rows that contain errors, whether they are constraint violations or failed update attempts. The RowError property or the SetColumnError( ) method of the DataRow object can be used to set an error, or an error can be set by the DataAdapter in response to errors that occur while data is being reconciled with the data source. The HasErrors( ) method should be called prior to calling GetErrors( ) to determine whether the call to GetErrors( ) is necessary. The following example shows how to use these methods:

DataRow[] errorRow;

if(dt.HasErrors())

{

    errorRows = dt.GetErrors();

    for(Int32 i = 0; i<errorRows.Length; i++)

    {

        // ... resolve the error for the row



        // clear the error for resubmitting

        errorRows[i].ClearErrors();

    }

}

Get ADO.NET in a Nutshell 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.