DataTable.AcceptChanges DataTable.AcceptChanges DataTable.AcceptChanges DataTable.AcceptChanges Method

Definição

Confirma todas as alterações feitas à tabela desde a última vez em que AcceptChanges() foi chamado.Commits all the changes made to this table since the last time AcceptChanges() was called.

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

Exemplos

O exemplo a seguir testa cada tabela em busca de erros.The following example tests each table for errors. Se os erros da tabela puderem ser reconciliados (passando-o para uma função indefinida) AcceptChanges , será chamado; caso RejectChanges contrário, será chamado.If the table's errors can be reconciled (by passing it to an undefined function), AcceptChanges is called; otherwise, RejectChanges is called.

   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

Comentários

Quando AcceptChanges é chamado, qualquer DataRow objeto que ainda esteja no modo de edição finalizará com êxito suas edições.When AcceptChanges is called, any DataRow object still in edit mode successfully ends its edits. O DataRowState também muda: todos Added e Modified linhas se Unchangedtornam e Deleted as linhas são removidas.The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed.

O AcceptChanges método é geralmente chamado em um DataTable depois que você tenta atualizar o DataSet usando o DbDataAdapter.Update método.The AcceptChanges method is generally called on a DataTable after you attempt to update the DataSet using the DbDataAdapter.Update method.

Aplica-se a

Veja também