DataRelation Constructor (String^, array<DataColumn^>^, array<DataColumn^>^, Boolean)
.NET Framework (current version)
Initializes a new instance of the DataRelation class using the specified name, matched arrays of parent and child DataColumn objects, and value that indicates whether to create constraints.
Assembly: System.Data (in System.Data.dll)
public: DataRelation( String^ relationName, array<DataColumn^>^ parentColumns, array<DataColumn^>^ childColumns, bool createConstraints )
Parameters
- relationName
-
Type:
System::String^
The name of the relation. If null or an empty string (""), a default name will be given when the created object is added to the DataRelationCollection.
- parentColumns
-
Type:
array<System.Data::DataColumn^>^
An array of parent DataColumn objects.
- childColumns
-
Type:
array<System.Data::DataColumn^>^
An array of child DataColumn objects.
- createConstraints
-
Type:
System::Boolean
A value that indicates whether to create constraints. true, if constraints are created. Otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentNullException | One or both of the DataColumn objects is null. |
| InvalidConstraintException |
The following example creates a new DataRelation and adds it to the DataRelationCollection of a DataSet.
Private Sub CreateRelation() ' Code to get the DataSet not shown here. ' Get the DataColumn objects from two DataTable ' objects in a DataSet. Dim parentColumns() As DataColumn Dim childColumns() As DataColumn parentColumns(0) = DataSet1.Tables( _ "Customers").Columns("CustID") parentColumns(1) = DataSet1.Tables( _ "Customers").Columns("OrdID") childColumns(0) = DataSet1.Tables( _ "Orders").Columns("CustID") childColumns(1) = DataSet1.Tables( _ "Orders").Columns("OrdID") Dim bConstraints As Boolean = True ' Create DataRelation. Dim CustOrderRel As DataRelation = New DataRelation( _ "CustomersOrders", parentColumns, childColumns, _ bConstraints) ' Add the relation to the DataSet. DataSet1.Relations.Add(CustOrderRel) End Sub
.NET Framework
Available since 1.1
Available since 1.1
Show: