ForeignKeyConstraint Class System.Data Namespace
Initializes a new instance of the ForeignKeyConstraint class with the specified arrays of parent and child DataColumn objects.
[ VB ]
Overloads Public Sub New ( _
ByVal parentColumns( ) As DataColumn, _
ByVal childColumns( ) As DataColumn _
)
[ C# ]
public ForeignKeyConstraint (
DataColumn [ ] parentColumns,
DataColumn [ ] childColumns
);
[ C++ ]
public: ForeignKeyConstraint (
DataColumn* parentColumns [ ],
DataColumn* childColumns [ ]
);
[ JScript ]
public function ForeignKeyConstraint (
parentColumns : DataColumn [ ],
childColumns : DataColumn [ ]
);
- parentColumns
- An array of parent DataColumn in the constraint.
- childColumns
- An array of 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 pCols ( 1 ) As DataColumn
Dim cCols ( 1 ) As DataColumn
Dim myFKC As ForeignKeyConstraint
' set parent and child column variables.
pCols ( 0 ) = myDataSet.Tables ( "OrderDetails" ).Columns ( "OrderID" )
pCols ( 1 ) = myDataSet.Tables ( "OrderDetails" ).Columns ( "ProductID" )
cCols ( 0 ) = myDataSet.Tables ( "Sales" ).Columns ( "OrderID" )
cCols ( 1 ) = myDataSet.Tables ( "Sales" ).Columns ( "ProductID" )
myFKC = New ForeignKeyConstraint ( pCols, cCols )
' set various properties of the constraint.
With myFKC
.RelationName = "ProductSalesOrders"
.DeleteRule = Rule.SetDefault
.UpdateRule = Rule.Cascade
.AcceptRejectRule = AcceptRejectRule.Cascade
End With
' add the constraint, and set EnforceConstraints to true.
myDataSet.Tables ( "OrderDetails" ).Constraints.Add myFKC
myDataSet.EnforceConstraints = True
End Sub
ForeignKeyConstraint Members ForeignKeyConstraint Constructor Overload List