Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DataRelation Constructor

.NET Framework 1.1

Initializes a new instance of the DataRelation class.

Overload List

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

Supported by the .NET Compact Framework.

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

Initializes a new instance of the DataRelation class using the specified DataRelation name and matched arrays of parent and child DataColumn objects.

Supported by the .NET Compact Framework.

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

Initializes a new instance of the DataRelation class using the specified name, parent and child DataColumn objects, and a value indicating whether to create constraints.

Supported by the .NET Compact Framework.

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

Initializes a new instance of the DataRelation class using the specified name, matched arrays of parent and child DataColumn objects, and value indicating whether to create constraints.

Supported by the .NET Compact Framework.

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

This constructor is provided for design time support in the Visual Studio .NET environment. Any DataRelation object 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(), String(), Boolean)
[C#] public DataRelation(string, string, string, string[], string[], bool);
[C++] public: DataRelation(String*, String*, String*, String*[], String*[], bool);
[JScript] public function DataRelation(String, String, String, String[], String[], Boolean);

Example

[Visual Basic] The following example creates a new DataRelation and adds it to the DataRelationCollection of a DataSet.

[Visual Basic] Note   This example shows how to use one of the overloaded versions of the DataRelation constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 

 Private Sub CreateRelation()
    ' Get the DataColumn objects from two DataTable objects in a DataSet.
    Dim parentCols() As DataColumn
    Dim childCols() As DataColumn
    ' Code to get the DataSet not shown here.
    parentCols(0) = DataSet1.Tables("Customers").Columns("CustID")
    parentCols(1) = DataSet1.Tables("Customers").Columns("OrdID")
 
    childCols(0) = DataSet1.Tables("Orders").Columns("CustID")
    childCols(1) = DataSet1.Tables("Orders").Columns("OrdID")
 
    Dim bConstraints As Boolean
    bConstraints = True
    ' Create DataRelation.
    Dim CustOrderRel As DataRelation
    CustOrderRel = New DataRelation("CustomersOrders", parentCols, childCols, bConstraints)
    ' Add the relation to the DataSet.
    DataSet1.Relations.Add(CustOrderRel)
 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

DataRelation Class | DataRelation Members | System.Data Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.