asp.net.ph

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

Parameters

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.

Exceptions


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

-Or -

The tables do not belong to the same DataSet.


Example

[ 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
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