NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

DataRelation Constructor (String, DataColumn[], DataColumn[])

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

[Visual Basic]
Overloads Public Sub New( _
   ByVal relationName As String, _
   ByVal parentColumns() As DataColumn, _
   ByVal childColumns() As DataColumn _
)
[C#]
public DataRelation(
   string relationName,
   DataColumn[] parentColumns,
   DataColumn[] childColumns
);
[C++]
public: DataRelation(
   String* relationName,
   DataColumn* parentColumns[],
   DataColumn* childColumns[]
);
[JScript]
public function DataRelation(
   relationName : String,
   parentColumns : DataColumn[],
   childColumns : DataColumn[]
);

Parameters

relationName
The name of the relation. If a null reference (in Visual Basic Nothing) or an empty string (""), a default name will be given when the created object is added to the RelationsCollection.
parentColumns
An array of parent DataColumn objects.
childColumns
An array of child DataColumn objects.

Exceptions

Exception Type Condition
ArgumentNullException Either one or both of the DataColumns is a a null reference (Nothing).
InvalidConstraintException The columns have differing data types

-Or-

One or both of the arrays are not composed of distinct columns from the same table.

-Or-

The tables don't belong to the same DataSet

Example [Visual Basic]

The following example creates a new DataRelation and adds it to a DataSet object's RelationsCollection.

[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")
   ' Create DataRelation.
   Dim relCustOrder As DataRelation
   CustOrderRel = New DataRelation("CustomersOrders", parentCols, childCols)
   ' Add the relation to the DataSet.
   DataSet1.Relations.Add(CustOrderRel)
End Sub

See Also

DataRelation Class | DataRelation Members | System.Data Namespace | DataRelation Constructor Overload List | DataColumn | ForeignKeyConstraint | RelationName