DataRow.ClearErrors Method

Definition

清除该行的错误。Clears the errors for the row. 这包括 RowErrorSetColumnError(Int32, String) 的错误设置。This includes the RowError and errors set with SetColumnError(Int32, String).

public:
 void ClearErrors();
public void ClearErrors ();
member this.ClearErrors : unit -> unit
Public Sub ClearErrors ()

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

使用 SetColumnErrorGetColumnError 设置和返回各个列的错误。Use SetColumnError and GetColumnError to set and return errors for individual columns.

设置 RowError 属性,以设置适用于整行的错误。Set the RowError property to set an error that applies to the whole row.

若要确定列集合是否存在任何错误,请使用 HasErrors 方法。To determine whether any errors exist for the columns collection, use the HasErrors method. 因此,您可以使用 GetColumnsInError 方法来检索所有包含错误的列。Consequently, you can use the GetColumnsInError method to retrieve all the columns with errors.

Applies to

See also