Bagikan melalui


AcceptRejectRule Enum

Definisi

Menentukan tindakan yang terjadi ketika AcceptChanges() metode atau RejectChanges() dipanggil pada DataTable dengan ForeignKeyConstraint.

public enum class AcceptRejectRule
public enum AcceptRejectRule
type AcceptRejectRule = 
Public Enum AcceptRejectRule
Warisan
AcceptRejectRule

Bidang

Cascade 1

Perubahan dikaskad di seluruh hubungan.

None 0

Tidak ada tindakan yang terjadi (default).

Contoh

Contoh berikut membuat ForeignKeyConstraint, mengatur berbagai propertinya, termasuk AcceptRejectRule, dan menambahkannya ke DataTable objek ConstraintCollection.

private void CreateConstraint(DataSet dataSet,
    string table1, string table2,string column1, string column2)
{
   // Declare parent column and child column variables.
   DataColumn parentColumn;
   DataColumn childColumn;
   ForeignKeyConstraint foreignKeyConstraint;

   // Set parent and child column variables.
   parentColumn = dataSet.Tables[table1].Columns[column1];
   childColumn = dataSet.Tables[table2].Columns[column2];
   foreignKeyConstraint = new ForeignKeyConstraint
      ("SupplierForeignKeyConstraint",  parentColumn, childColumn);

   // Set null values when a value is deleted.
   foreignKeyConstraint.DeleteRule = Rule.SetNull;
   foreignKeyConstraint.UpdateRule = Rule.Cascade;
   foreignKeyConstraint.AcceptRejectRule = AcceptRejectRule.None;

   // Add the constraint, and set EnforceConstraints to true.
   dataSet.Tables[table1].Constraints.Add(foreignKeyConstraint);
   dataSet.EnforceConstraints = true;
}
Private Sub CreateConstraint(dataSet As DataSet, _
   table1 As String, table2 As String, _
   column1 As String, column2 As String)

   ' Declare parent column and child column variables.
   Dim parentColumn As DataColumn
   Dim childColumn As DataColumn
   Dim foreignKeyConstraint As ForeignKeyConstraint

   ' Set parent and child column variables.
   parentColumn = dataSet.Tables(table1).Columns(column1)
   childColumn = dataSet.Tables(table2).Columns(column2)
   foreignKeyConstraint = New ForeignKeyConstraint _
      ("SupplierForeignKeyConstraint", parentColumn, childColumn)

   ' Set null values when a value is deleted.
   foreignKeyConstraint.DeleteRule = Rule.SetNull
   foreignKeyConstraint.UpdateRule = Rule.Cascade
   foreignKeyConstraint.AcceptRejectRule = AcceptRejectRule.None

   ' Add the constraint, and set EnforceConstraints to true.
   dataSet.Tables(table1).Constraints.Add(foreignKeyConstraint)
   dataSet.EnforceConstraints = True
End Sub

Keterangan

Perubahan pada DataTable tidak final sampai Anda memanggil AcceptChanges metode . Saat atau AcceptChangesRejectChanges dipanggil pada baris dalam tabel induk, AcceptRejectRule nilai menentukan apakah perubahan disebarluaskan ke baris terkait dalam tabel anak atau tidak.

Berlaku untuk

Lihat juga