View Single Post
  #3 (permalink)  
Old March 24th, 2007, 06:38 AM
erictamlam erictamlam is offline
Authorized User
 
Join Date: Mar 2007
Location: Beijing, Beijing, China.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to erictamlam Send a message via MSN to erictamlam Send a message via Yahoo to erictamlam
Default

You can use "DataRelation" object to create relationship between parent table and child table...of course you hafta fill DataSet with tables with DataAdapter object.
for example:Parent table:Order[primary key:"OrderID"] Child table:OrderDetail[foreign key:"OrderID"]
you can create bond between them like this: DataRelation orderRel=thisDataSet.Relations.Add("orderbond",thi sDataSet.Tables["Order"].Colums["OrderID"],thisDataSet.Tables["OrderDetail"].Colums["OrderID"]);
then use "foreach" statement..."OrderID" in Parent Table will be automatically passes to Child Table:
 for each(DataRow orderRow in thisDataSet.Tables["Order"].Rows)
{
   ....//parent table processing
    foreach(DataRow orderDetailRow in orderRow.GetChildRows(orderRel) )
    .....//Child table processing
}
sometimes .GetParentRows can also come into handy.
Hope this can help.


ERIC
Reply With Quote