Editare

Partajați prin


DataRow.GetColumnsInError Method

Definition

Gets an array of columns that have errors.

public:
 cli::array <System::Data::DataColumn ^> ^ GetColumnsInError();
public System.Data.DataColumn[] GetColumnsInError ();
member this.GetColumnsInError : unit -> System.Data.DataColumn[]
Public Function GetColumnsInError () As DataColumn()

Returns

An array of DataColumn objects that contain errors.

Examples

The following example uses the HasErrors to look for errors. If the row has errors, the GetColumnsInError method returns the array of columns with errors that can then be resolved. The ClearErrors method is then called to clear all errors.

private void GetAllErrs(DataRow row)
{
    // Declare an array variable for DataColumn objects.
    DataColumn[] colArr;
    // If the Row has errors, check use GetColumnsInError.
    if(row.HasErrors)
    {
        // Get the array of columns in error.
        colArr = row.GetColumnsInError();
        for(int i = 0; i < colArr.Length; i++)
        {
            // Insert code to fix errors on each column.
            Console.WriteLine(colArr[i].ColumnName);
        }
        // Clear errors after reconciling.
        row.ClearErrors();
    }
}
Private Sub GetAllErrs(ByVal row As DataRow)
    ' Declare an array variable for DataColumn objects.
    Dim colArr() As DataColumn 

    ' If the Row has errors, check use GetColumnsInError.
    Dim i As Integer
    If row.HasErrors Then 
       ' Get the array of columns in error.
       colArr = row.GetColumnsInError()
       For i = 0 to colArr.GetUpperBound(0)
          ' Insert code to fix errors on each column.
          Console.WriteLine(colArr(i).ColumnName)
       Next i

    ' Clear errors after reconciling.
    row.ClearErrors()
    End If
 End Sub

Remarks

The GetColumnsInError lets you reduce the number of DataColumn objects that must be processed for errors by returning only those columns that have an error. Errors can be set to individual columns with the SetColumnError method. To further reduce the number of processing, examine the HasErrors property of the DataRow class to determine whether a DataRow has errors before invoking GetColumnsInError.

Use the ClearErrors method to clear all errors on the row. This includes the RowError.

Applies to

See also