asp.net.ph

ForeignKeyConstraint Constructor ( String, DataColumn, DataColumn )

ForeignKeyConstraint Class   System.Data Namespace


Initializes a new instance of the ForeignKeyConstraint class with the specified name, parent and child DataColumn objects.

[ VB ]
Overloads Public Sub New ( _
   ByVal constraintName As String, _
   ByVal parentColumn As DataColumn, _
   ByVal childColumn As DataColumn _
)

[ C# ]
public ForeignKeyConstraint (
   string constraintName,
   DataColumn parentColumn,
   DataColumn childColumn
);

[ C++ ]
public: ForeignKeyConstraint (
   String* constraintName,
   DataColumn* parentColumn,
   DataColumn* childColumn
);

[ JScript ]
public function ForeignKeyConstraint (
   constraintName : String,
   parentColumn : DataColumn,
   childColumn : DataColumn
);

Parameters

constraintName
The name of the constraint.
parentColumn
The parent DataColumn in the constraint.
childColumn
The 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

[ 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 ( "SuppierFKConstraint", pCol, cCol )
   ' set various properties of the constraint.
   With myFKC
      .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
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