DataRow.ClearErrors 方法

定義

清除資料列的錯誤。 這包括 RowError 和以 SetColumnError(Int32, String) 設定的錯誤。

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

範例

下列範例會使用 HasErrors 尋找錯誤。 如果資料列有錯誤, GetColumnsInError 此方法會傳回資料行的陣列,並接著可以解決這些錯誤。 ClearErrors接著會呼叫 方法來清除所有錯誤。

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 來設定和傳回個別資料行的錯誤。

RowError設定 屬性以設定套用至整個資料列的錯誤。

若要判斷資料行集合是否有任何錯誤,請使用 HasErrors 方法。 因此,您可以使用 GetColumnsInError 方法來擷取所有發生錯誤的資料行。

適用於

另請參閱