ForeignKeyConstraint Class System.Data Namespace
Initializes a new instance of the ForeignKeyConstraint class with the specified name, and arrays of parent and child DataColumn objects.
[ VB ]
Overloads Public Sub New ( _
ByVal constraintName As String, _
ByVal parentColumns( ) As DataColumn, _
ByVal childColumns( ) As DataColumn _
)
[ C# ]
public ForeignKeyConstraint (
string constraintName,
DataColumn [ ] parentColumns,
DataColumn [ ] childColumns
);
[ C++ ]
public: ForeignKeyConstraint (
String* constraintName,
DataColumn* parentColumns [ ],
DataColumn* childColumns [ ]
);
[ JScript ]
public function ForeignKeyConstraint (
constraintName : String,
parentColumns : DataColumn [ ],
childColumns : DataColumn [ ]
);
- constraintName
- The name of the ForeignKeyConstraint. If a null reference ( in Visual Basic Nothing ) or empty string, a default name will be given when added to the constraints collection.
- parentColumns
- An array of parent DataColumn in the constraint.
- childColumns
- An array of child DataColumn in the constraint.
[ 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 ( "ProductSalesOrders", pCols, cCols )
' set various properties of the constraint.
With myFKC
.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