DataRow.GetColumnsInError 方法

定义

获取由包含错误的列组成的数组。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()

返回

DataColumn[]

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

示例

下面的示例使用 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

注解

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. 可以通过方法将错误设置为单独的列 SetColumnErrorErrors can be set to individual columns with the SetColumnError method. 若要进一步减少处理次数,请检查 HasErrors 类的属性, DataRow 以确定在 DataRow 调用之前是否有错误 GetColumnsInErrorTo 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.

适用于

另请参阅