ForeignKeyConstraint Class System.Data Namespace
Indicates what kind of action should take place across this constraint when AcceptChanges is invoked.
[ VB ]
Overridable Public Property AcceptRejectRule As AcceptRejectRule
[ C# ]
public AcceptRejectRule AcceptRejectRule {virtual get; virtual
set;}
[ C++ ]
public: __property virtual AcceptRejectRule get_AcceptRejectRule ( );
public: __property virtual void set_AcceptRejectRule ( AcceptRejectRule );
[ JScript ]
public function get AcceptRejectRule ( ) : AcceptRejectRule;
public function set AcceptRejectRule ( AcceptRejectRule );
One of the AcceptRejectRule values. Possible values include None, Cascade, and Default.
Changes to a DataRow or DataTable are not final until the Accept method is invoked. At that point, the AcceptRejectRule will determine the course of action on any values that have been changed or deleted.
The following example initializes a ForeignKeyConstraint, sets its AcceptRejectRule, and adds the constraint to a DataTable object's ConstraintsCollection.
[ VB ]
' the next line goes into the Declarations section of the module:
' suppliersProducts is a class derived from DataSet.
Private myDataSet As SuppliersProducts
Private Sub CreateConstraint ( )
' declare parent column and child column variables.
Dim pCol As DataColumn
Dim cCol As DataColumn
Dim myFKC As ForeignKeyConstraint
' set parent and child column variables.
pCol = myDataSet.Tables ( "Suppliers ).Columns ( "SupplierID" )
cCol = myDataSet.Tables ( "Products" ).Columns ( "SupplieriD" )
myFKC = New ForeignKeyConstraint ( "SuppierFKConstraint", pCol, cCol )
' set null values when a value is deleted.
myFKC.DeleteRule = Rule.SetNull
myFKC.UpdateRule = Rule.Cascade
myFKC.AcceptRejectRule = AcceptRejectRule.Cascade
' add the constraint, and set EnforceConstraints to true.
myDataSet.Tables ( "Suppliers" ).Constraints.Add myFKC
myDataSet.EnforceConstraints = True
End Sub
ForeignKeyConstraint Members AcceptRejectRule