DataRow.GetColumnsInError Metod

Definition

Hämtar en matris med kolumner som har fel.

public:
 cli::array <System::Data::DataColumn ^> ^ GetColumnsInError();
public System.Data.DataColumn[] GetColumnsInError();
member this.GetColumnsInError : unit -> System.Data.DataColumn[]
Public Function GetColumnsInError () As DataColumn()

Returer

En matris med DataColumn objekt som innehåller fel.

Exempel

I följande exempel används HasErrors för att söka efter fel. Om raden har fel returnerar GetColumnsInError metoden matrisen med kolumner med fel som sedan kan lösas. Metoden ClearErrors anropas sedan för att rensa alla fel.

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

Kommentarer

Med GetColumnsInError kan du minska antalet DataColumn objekt som måste bearbetas för fel genom att endast returnera de kolumner som har ett fel. Fel kan anges till enskilda kolumner med SetColumnError metoden . Om du vill minska antalet bearbetningar ytterligare undersöker du HasErrors egenskapen för DataRow klassen för att avgöra om en DataRow har fel innan du anropar GetColumnsInError.

ClearErrors Använd metoden för att rensa alla fel på raden. Detta inkluderar RowError.

Gäller för

Se även