System.Data Namespace DataRelationCollection Class
Adds a DataRelation with the given name, and parent and child columns to the collection.
[ VB ]
Overridable Overloads Public Function Add ( _
ByVal name As String, _
ByVal parentColumn As DataColumn, _
ByVal childColumn As DataColumn _
) As DataRelation
[ C# ]
public virtual DataRelation Add (
string name,
DataColumn parentColumn,
DataColumn childColumn
);
[ C++ ]
public: virtual DataRelation* Add (
String* name,
DataColumn* parentColumn,
DataColumn* childColumn
);
[ JScript ]
public function Add (
name : String,
parentColumn : DataColumn,
childColumn : DataColumn
) : DataRelation;
- name
- The name of the relation.
- parentColumn
- The parent column of the relation.
- childColumn
- The child column of the relation.
The newly created DataRelation.
Exception Type |
Condition |
ArgumentException |
Occurs when the relation already belongs to this collection, or it belongs to another collection. |
DuplicateNameException |
Occurs when the collection already has a relation with the specified name. The comparison is case insensitive. |
InvalidConstraintException |
Occurs when the relation cannot be created based on the given parameters. |
This version of the Add method creates a relation given the above parameters and adds it to the collection. The CollectionChanged event is fired if it succeeds.
The following example adds a new DataRelation using this version of the Add method.
ds.Relations.Add ( "categoryId",
ds.Tables [ 0 ].Columns [ "CategoryID" ],
ds.Tables [ 1 ].Columns [ "CategoryID" ] );
ds.Relations.Add ( "categoryId" _
ds.Tables ( 0 ).Columns ( "CategoryID" ), _
ds.Tables ( 1 ).Columns ( "CategoryID" ) ) |
|
C# |
VB |
DataRelationCollection Members DataRelationCollection.Add Overload List