DataTable.AcceptChanges Metodo

Definizione

Convalida tutte le modifiche apportate a questa tabella sin dall'ultima chiamata al metodo AcceptChanges().

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

Esempio

L'esempio seguente verifica ogni tabella per gli errori. Se gli errori della tabella possono essere riconciliati (passandolo a una funzione non definita), AcceptChanges viene chiamato; in caso contrario, RejectChanges viene chiamato.

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

Commenti

Quando AcceptChanges viene chiamato, qualsiasi DataRow oggetto ancora in modalità di modifica termina correttamente le modifiche. Cambia DataRowState anche: tutte le Added Modified righe diventano e Deleted le righe Unchangedvengono rimosse.

Il AcceptChanges metodo viene in genere chiamato su un DataTable oggetto dopo aver tentato di aggiornare l'uso DataSet del DbDataAdapter.Update metodo .

Si applica a

Vedi anche