DataTable.AcceptChanges Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Son çağrılışından AcceptChanges() bu yana bu tabloda yapılan tüm değişiklikleri işler.
public:
void AcceptChanges();
public void AcceptChanges ();
member this.AcceptChanges : unit -> unit
Public Sub AcceptChanges ()
Örnekler
Aşağıdaki örnek, her tabloyu hatalara karşı test ediyor. Tablonun hataları uzlaştırılabilirse (tanımlanmamış bir işleve geçirilerek) AcceptChanges çağrılır; aksi takdirde RejectChanges çağrılır.
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
Açıklamalar
Çağrıldığında AcceptChanges , hala düzenleme modunda olan tüm DataRow nesneler düzenlemelerini başarıyla sonlandırır. ayrıca DataRowState değişir: tüm Added
ve Modified
satırlar olur Unchanged
ve Deleted
satırlar kaldırılır.
AcceptChanges yöntemini kullanarak güncelleştirme DataSet girişiminde bulunduktan sonra yöntemi genellikle üzerinde DataTable çağrılırDbDataAdapter.Update.
Şunlara uygulanır
Ayrıca bkz.
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin