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

DataColumn[]

包含错误的 DataColumn 对象组成的数组。An array of DataColumn objects that contain errors.

Examples

下面的示例使用 HasErrors 来查找错误。The following example uses the HasErrors to look for errors. 如果行有错误,GetColumnsInError 方法将返回列的数组,其中包含可解决的错误。If the row has errors, the GetColumnsInError method returns the array of columns with errors that can then be resolved. 然后调用 ClearErrors 方法以清除所有错误。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

使用 GetColumnsInError 可以通过仅返回那些包含错误的列来减少必须处理错误的 DataColumn 对象的数量。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. 可以将错误设置为具有 SetColumnError 方法的各个列。Errors can be set to individual columns with the SetColumnError method. 若要进一步减少处理次数,请检查 DataRow 类的 HasErrors 属性,以确定 DataRow 在调用 GetColumnsInError之前是否有错误。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.

使用 ClearErrors 方法可清除行中的所有错误。Use the ClearErrors method to clear all errors on the row. 其中包括 RowErrorThis includes the RowError.

Applies to

See also