DataRow.ClearErrors 方法

定義

清除資料列的錯誤。Clears the errors for the row. 這包括 RowError 和以 SetColumnError(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 ()

範例

下列範例會使用 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

備註

使用 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.

適用於

另請參閱