Export (0) Print
Expand All

ForeignKeyConstraint Constructor

.NET Framework 1.1

Initializes a new instance of the ForeignKeyConstraint class.

Overload List

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(DataColumn, DataColumn)
[C#] public ForeignKeyConstraint(DataColumn, DataColumn);
[C++] public: ForeignKeyConstraint(DataColumn*, DataColumn*);
[JScript] public function ForeignKeyConstraint(DataColumn, DataColumn);

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(DataColumn(), DataColumn())
[C#] public ForeignKeyConstraint(DataColumn[], DataColumn[]);
[C++] public: ForeignKeyConstraint(DataColumn*[], DataColumn*[]);
[JScript] public function ForeignKeyConstraint(DataColumn[], DataColumn[]);

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(String, DataColumn, DataColumn)
[C#] public ForeignKeyConstraint(string, DataColumn, DataColumn);
[C++] public: ForeignKeyConstraint(String*, DataColumn*, DataColumn*);
[JScript] public function ForeignKeyConstraint(String, DataColumn, DataColumn);

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(String, DataColumn(), DataColumn())
[C#] public ForeignKeyConstraint(string, DataColumn[], DataColumn[]);
[C++] public: ForeignKeyConstraint(String*, DataColumn[], DataColumn[]);
[JScript] public function ForeignKeyConstraint(String, DataColumn[], DataColumn[]);

This constructor is provided for design time support in the Visual Studio .NET environment. ForeignKeyConstraint objects created by using this constructor must then be added to the collection via AddRange. Tables and columns with the specified names must exist at the time the method is called, or if BeginInit has been called prior to calling this constructor, the tables and columns with the specified names must exist at the time that EndInit is called.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(String, String, String(), String(), AcceptRejectRule, Rule, Rule)
[C#] public ForeignKeyConstraint(string, string, string[], string[], AcceptRejectRule, Rule, Rule);
[C++] public: ForeignKeyConstraint(String*, String*, String*[], String*[], AcceptRejectRule, Rule, Rule);
[JScript] public function ForeignKeyConstraint(String, String, String[], String[], AcceptRejectRule, Rule, Rule);

Example

[Visual Basic] The following example creates a new ForeignKeyConstraint, sets some of its properties, and adds it to a DataTable object's ConstraintCollection.

[Visual Basic] Note   This example shows how to use one of the overloaded versions of the ForeignKeyConstraint constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' 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

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ForeignKeyConstraint Class | ForeignKeyConstraint Members | System.Data Namespace

Show:
© 2014 Microsoft