6.3 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:


The Contains( ) method can determine if a specific relation exists as shown in the following example:

 Boolean exists = ds.Relations.Contains("MyRelation"); 

Relations and the DataRelationCollection are discussed in detail in Chapter 11.

ADO. NET in a Nutshell
ADO.NET in a Nutshell
ISBN: 0596003617
EAN: 2147483647
Year: 2005
Pages: 415

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net