asp.net.ph

ForeignKeyConstraint Constructor ( DataColumn [ ], DataColumn [ ] )

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 [ ]
);

Parameters

parentColumns
An array of parent DataColumn in the constraint.
childColumns
An array of child DataColumn in the constraint.

Exceptions


Exception Type Condition
ArgumentNullException Occurs when One or both of the columns is a null reference ( in Visual Basic Nothing ).
InvalidConstraintException Occurs when the columns have different data types.

-Or -

The tables do not belong to the same DataSet.


Example

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
See Also

ForeignKeyConstraint Members   ForeignKeyConstraint Constructor Overload List Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph