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, parent, and child columns.

[Visual Basic]
Overloads Public Sub New( _
   ByVal relationName As String, _
   ByVal parentColumn As DataColumn, _
   ByVal childColumn As DataColumn _
)
[C#]
public DataRelation(
   string relationName,
   DataColumn parentColumn,
   DataColumn childColumn
);
[C++]
public: DataRelation(
   String* relationName,
   DataColumn* parentColumn,
   DataColumn* childColumn
);
[JScript]
public function DataRelation(
   relationName : String,
   parentColumn : DataColumn,
   childColumn : 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.
parentColumn
The parent DataColumn in the relation.
childColumn
The child DataColumn in the relation.

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-

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 parentCol As DataColumn
   Dim childCol As DataColumn
   ' Code to get the DataSet not shown here.
   parentCol = DataSet1.Tables("Customers").Columns("CustID")
   childCol = DataSet1.Tables("Orders").Columns("CustID")
   ' Create DataRelation.
   Dim relCustOrder As DataRelation
   CustOrderRel = New DataRelation("CustomersOrders", parentCol, childCol)
   ' 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 | RelationName