DataTable.AcceptChanges Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Faz commit de todas as alterações feitas a esta tabela desde a última vez AcceptChanges() que foi chamada.
public:
void AcceptChanges();
public void AcceptChanges();
member this.AcceptChanges : unit -> unit
Public Sub AcceptChanges ()
Exemplos
O exemplo seguinte testa cada tabela quanto a erros. Se os erros da tabela puderem ser reconciliados (passando-a para uma função indefinida), AcceptChanges é chamado; caso contrário, RejectChanges é chamado.
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
Observações
Quando AcceptChanges é chamado, qualquer DataRow objeto ainda em modo de edição termina com sucesso as suas edições. Também muda DataRowState : todas Added as linhas e Modified tornam-se Unchanged, e Deleted as linhas são removidas.
O AcceptChanges método é geralmente chamado a DataTable depois de tentar atualizar o DataSet usando o DbDataAdapter.Update método.