ForeignKeyConstraint.DeleteRule 屬性

定義

取得或設定資料列刪除時會跨越這個條件約束發生的動作。

public:
 virtual property System::Data::Rule DeleteRule { System::Data::Rule get(); void set(System::Data::Rule value); };
public virtual System.Data.Rule DeleteRule { get; set; }
[System.Data.DataSysDescription("ForeignKeyConstraintDeleteRuleDescr")]
public virtual System.Data.Rule DeleteRule { get; set; }
member this.DeleteRule : System.Data.Rule with get, set
[<System.Data.DataSysDescription("ForeignKeyConstraintDeleteRuleDescr")>]
member this.DeleteRule : System.Data.Rule with get, set
Public Overridable Property DeleteRule As Rule

屬性值

其中一個 Rule 值。 預設為 Cascade

屬性

範例

下列範例會建立ForeignKeyConstraint、設定其各種屬性,並將它新增至 DataTable 物件的 ConstraintCollection

' The next line goes into the Declarations section of the module:
' SuppliersProducts is a class derived from DataSet.
Private suppliersProducts As SuppliersProducts 

Private Sub CreateConstraint()
   ' Declare parent column and child column variables.
   Dim parentColumn As DataColumn
   Dim childColumn As DataColumn
   Dim fkConstraint As ForeignKeyConstraint

   ' Set parent and child column variables.
   parentColumn = suppliersProducts.Tables("Suppliers").Columns("SupplierID")
   childColumn = suppliersProducts.Tables("Products").Columns("SupplieriD")
   fkConstraint = New ForeignKeyConstraint( _
       "SuppierFKConstraint", parentColumn, childColumn)

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

   ' Add the constraint, and set EnforceConstraints to true.
   suppliersProducts.Tables("Suppliers").Constraints.Add(fkConstraint)
   suppliersProducts.EnforceConstraints = True
End Sub

備註

從父數據表中刪除數據列時,會 DeleteRule 決定子數據表數據行 (或數據表) 會發生什麼情況。 如果規則設定為 Cascade,則會刪除子數據列。

如果設定為 SetNullDBNull 則會將 放在受影響數據列的適當數據行中。 視您的數據源而定,數據行中可能會允許或不允許 Null 值。 例如,SQL Server 允許在主鍵數據行中找到多個 Null 值,即使它們不是唯一的。 DataTable不過,在 中,如果DataColumn對象的 Unique 屬性設定為 true,主鍵數據行中不允許多個 Null 值。

如果設定為 SetDefault,則會指派數據行的預設值。

適用於