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 物件陣列。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. 您可以使用 SetColumnError 方法,將錯誤設定為個別的資料行。Errors can be set to individual columns with the SetColumnError method. 若要進一步減少處理的數目,請檢查 DataRow 類別的 HasErrors 屬性,以判斷 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.

適用於

另請參閱