AcceptRejectRule 枚举

定义

确定在带有 AcceptChanges()RejectChanges() 上调用 DataTableForeignKeyConstraint 方法时将发生的操作。

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 对 的更改不是最终的 AcceptChangesAcceptChanges对父表中的某一行调用 或 RejectChanges 时,AcceptRejectRule该值确定是否将更改传播到子表中的相应行。

适用于

另请参阅