27.1 CommentsTroubleshooting

27.1 Comments/Troubleshooting

DataRelation objects are contained in a DataRelationCollection . Every DataSet exposes a DataRelationCollection through its Relations property. In addition, you can access the DataRelation objects that pertain to a specific table through the DataTable.ChildRelations and DataTable.ParentRelations properties.

The DataRelation links two matching DataColumn objects from different tables. Thus, the data type of both columns must be identical. When a DataRelation object is created, the relationship is verified . Once you add the DataRelation to the DataSet.Relations collection, a ForeignKeyConstraint is generated for the child table, preventing changes that would violate relational integrity.

The following code creates and adds a DataRelation :

 DataColumn parentCol = ds.Tables["Categories"].Columns["CategoryID"]; DataColumn childCol = ds.Tables["Products"].Columns["CategoryID"]; DataRelation dr = new DataRelation("Cat_Prod", parentCol, childCol); ds.Relations.Add(dr); 

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