DataTable.AcceptChanges Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Фиксирует все изменения, внесенные в эту таблицу с момента последнего AcceptChanges() вызова.
public:
void AcceptChanges();
public void AcceptChanges();
member this.AcceptChanges : unit -> unit
Public Sub AcceptChanges ()
Примеры
В следующем примере проверяется каждая таблица ошибок. Если ошибки таблицы можно примирить (передав ее в неопределенную функцию), AcceptChanges вызывается; в противном случае RejectChanges вызывается.
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
Комментарии
При AcceptChanges вызове любой DataRow объект по-прежнему в режиме редактирования успешно завершает свои изменения. Изменения DataRowState также: все Added и Modified строки становятся Unchanged, а Deleted строки удаляются.
Метод AcceptChanges обычно вызывается DataTable после попытки обновить DataSet метод с помощью DbDataAdapter.Update метода.