共用方式為


AcceptRejectRule 列舉

定義

判斷在具有 ForeignKeyConstraintDataTable 上叫用 AcceptChanges()RejectChanges() 方法時會發生的動作。

public enum class AcceptRejectRule
public enum AcceptRejectRule
type AcceptRejectRule = 
Public Enum AcceptRejectRule
繼承
AcceptRejectRule

欄位

Cascade 1

跨越關聯性來串聯變更。

None 0

未發生任何動作 (預設值)。

範例

下列範例會 ForeignKeyConstraint建立 、設定其各種屬性,包括 AcceptRejectRule,並將它新增至 DataTable 物件的 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

備註

DataTable直到您呼叫 方法之後,AcceptChanges變更才會結束。 AcceptChanges在父數據表的數據列上呼叫 或 RejectChanges 時,AcceptRejectRule值會決定是否將變更傳播至子數據表中的對應數據列。

適用於

另請參閱