ForeignKeyConstraint Class System.Data Namespace
Initializes a new instance of the ForeignKeyConstraint class with the specified parent and child DataColumn objects.
[ VB ]
Overloads Public Sub New ( _
ByVal parentColumn As DataColumn, _
ByVal childColumn As DataColumn _
)
[ C# ]
public ForeignKeyConstraint (
DataColumn parentColumn,
DataColumn childColumn
);
[ C++ ]
public: ForeignKeyConstraint (
DataColumn* parentColumn,
DataColumn* childColumn
);
[ JScript ]
public function ForeignKeyConstraint (
parentColumn : DataColumn,
childColumn : DataColumn
);
- parentColumn
- The parent DataColumn in the constraint.
- childColumn
- The child DataColumn in the constraint.
The following example initializes a new ForeignKeyConstraint, sets various of its properties, and adds it 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 ( pCol, cCol )
' set various properties of the constraint.
With myFKC
.RelationName = "SuppierFKConstraint"
.DeleteRule = Rule.SetNull
.UpdateRule = Rule.Cascade
.AcceptRejectRule = AcceptRejectRule.Cascade
End With
' add the constraint, and set EnforceConstraints to true.
myDataSet.Tables ( "Suppliers" ).Constraints.Add myFKC
myDataSet.EnforceConstraints = True
End Sub
ForeignKeyConstraint Members ForeignKeyConstraint Constructor Overload List