Adding and Removing Relations
Relations belonging to the DataSet are stored as DataRelation objects in a DataRelationCollection object and are accessed through the Relations property of the DataSet. Each DataRelation object represents the relationship between a parent and child table in the DataSet. This section examines some methods and properties of the DataRelationCollection.
Relations are added to the DataSet using the Add( ) method of the DataRelationCollection, as shown in the following example:
ds.Relations.Add("MyDataRelation", parentTable.Columns["PrimaryKeyField"],
childTable.Columns["ForeignKeyField"]);
The Remove( ) method removes a relation matching the relation-name argument. The following example removes the relation added in the previous example:
ds.Relations.Remove("MyDataRelation");
The Contains( ) method can determine if a specific relation exists as shown in the following example:
Boolean exists = ds.Relations.Contains("MyRelation");
No comments:
Post a Comment