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[] );
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 |
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
DataRelation Class | DataRelation Members | System.Data Namespace | DataRelation Constructor Overload List | DataColumn | ForeignKeyConstraint | RelationName