DataTable.AcceptChanges Metod

Definition

Genomför alla ändringar som gjorts i den här tabellen sedan den senaste gången AcceptChanges() anropades.

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

Exempel

I följande exempel testas varje tabell efter fel. Om tabellens fel kan stämmas av (genom att skicka den till en odefinierad funktion) AcceptChanges anropas, annars RejectChanges anropas.

private void AcceptOrReject(DataTable table)
{
    // If there are errors, try to reconcile.
    if(table.HasErrors)
    {
        if(Reconcile(table))
        {
            // Fixed all errors.
            table.AcceptChanges();
        }
        else
        {
            // Couldn'table fix all errors.
            table.RejectChanges();
        }
    }
    else
    {
        // If no errors, AcceptChanges.
        table.AcceptChanges();
    }
}

private bool Reconcile(DataTable thisTable)
{
    foreach(DataRow row in thisTable.Rows)
    {
        //Insert code to try to reconcile error.

        // If there are still errors return immediately
        // since the caller rejects all changes upon error.
        if(row.HasErrors)
            return false;
    }
    return true;
}
Private Sub AcceptOrReject(table As DataTable)
    ' If there are errors, try to reconcile.
        If (table.HasErrors) Then
            If (Reconcile(table)) Then
                ' Fixed all errors.
                table.AcceptChanges()
            Else
                ' Couldn'table fix all errors.
                table.RejectChanges()
            End If
        Else
            ' If no errors, AcceptChanges.
            table.AcceptChanges()
        End If
 End Sub
 
Private Function Reconcile(thisTable As DataTable) As Boolean
    Dim row As DataRow
    For Each row in thisTable.Rows
       'Insert code to try to reconcile error.

       ' If there are still errors return immediately
       ' since the caller rejects all changes upon error.
       If row.HasErrors Then
           Reconcile = False
           Exit Function
       End If
    Next row
    Reconcile = True
 End Function

Kommentarer

När AcceptChanges anropas avslutas alla DataRow objekt som fortfarande är i redigeringsläge sina redigeringar. Ändringarna DataRowState ändras också: alla Added rader och Modified rader blir Unchanged, och Deleted rader tas bort.

Metoden AcceptChanges anropas vanligtvis på en DataTable när du försöker uppdatera med hjälp av DataSetDbDataAdapter.Update metoden.

Gäller för

Se även