System.Data Namespace DataRelation Class
Initializes a new instance of the DataRelation class using the specified DataRelation name and matched arrays of parent and child DataColumn objects.
[ VB ]
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 [ ]
);
- relationName
- The name of the relation. If a null reference or an empty string ( "" ), a default name will be given when the created object is added to the DataRelationCollection.
- parentColumns
- An array of parent DataColumn objects.
- childColumns
- An array of child DataColumn objects.
Exception Type |
Condition |
ArgumentNullException |
Occurs when Either one or both of the DataColumns is a null reference ( Nothing ). |
InvalidConstraintException |
Occurs when
- the columns have differing data types
- one or both of the arrays are not composed of distinct columns from the same table.
- the tables do not belong to the same DataSet
|
The following example initializes a new DataRelation using this constructor, and adds it to the DataRelationCollection of a DataSet.
DataColumn parentCols [ ];
parentCols [ 0 ] = ds.Tables [ "Categories" ].Columns [ "CategoryID" ];
DataColumn childCols [ ];
childCols [ 0 ] = ds.Tables [ "Products" ].Columns [ "CategoryID" ];
DataRelation categoryId = new DataRelation ( "categoryId", parentCols, childCols );
// add the relation to the DataSet.
ds.Relations.Add ( categoryId );
Dim parentCols ( ) As DataColumn
parentCols ( 0 ) = ds.Tables ( "Categories" ).Columns ( "CategoryID" )
Dim childCols ( ) As DataColumn
childCols ( 0 ) = ds.Tables ( "Products" ).Columns ( "CategoryID" )
Dim categoryId As New DataRelation ( "categoryId", parentCols, childCols )
' add the relation to the DataSet.
ds.Relations.Add ( categoryId ) |
|
C# |
VB |
DataRelation Members DataRelation Constructor Overload List DataColumn ForeignKeyConstraint RelationName