DataRelation.ChildKeyConstraint 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得關聯的 ForeignKeyConstraint。
public:
virtual property System::Data::ForeignKeyConstraint ^ ChildKeyConstraint { System::Data::ForeignKeyConstraint ^ get(); };
public virtual System.Data.ForeignKeyConstraint? ChildKeyConstraint { get; }
public virtual System.Data.ForeignKeyConstraint ChildKeyConstraint { get; }
member this.ChildKeyConstraint : System.Data.ForeignKeyConstraint
Public Overridable ReadOnly Property ChildKeyConstraint As ForeignKeyConstraint
屬性值
ForeignKeyConstraint
。
範例
下列範例會UpdateRule
設定與相關聯 之的DataRelation
、 DeleteRule
和 AcceptReject
規則ForeignKeyConstraint
。
Private Sub SetChildKeyConstraint(dataSet As DataSet)
' Set child and parent columns.
Dim parentColumn As DataColumn = dataSet.Tables( _
"Suppliers").Columns("SupplierID")
Dim childColumn As DataColumn = dataSet.Tables( _
"Products").Columns("SupplierID")
Dim relation As New DataRelation( _
"SuppliersConstraint", parentColumn, childColumn)
dataSet.Relations.Add(relation)
Dim foreignKey As ForeignKeyConstraint = _
relation.ChildKeyConstraint
foreignKey.DeleteRule = Rule.SetNull
foreignKey.UpdateRule = Rule.Cascade
foreignKey.AcceptRejectRule = AcceptRejectRule.Cascade
End Sub
備註
如果這個關聯性沒有任何關聯的 ForeignKeyConstraint 存在,當關聯性加入至關聯集合時,就會自動建立該關聯性,並由 ChildKeyConstraint
指向 。