>open database "C:\Program Files\Microsoft Visual FoxPro 7\Samples\Data\testdata.dbc" >use customer >use orders in 0 order cust_id >set relation to cust_id into orders > >scan > ? customers.cust_id > select orders > scan while cust_id = customers.cust_id > ? chr(9), orders.order_id, chr(9), customers.company > endscan >endscan >>
>using System; >using System.Data; >using System.Data.OleDb; > >namespace RelatedDataset >{ > class Class1 > { > [STAThread] > static void Main(string[] args) > { > string strcon,strsql1,strsql2; > strcon = @"Provider=VFPOLEDB;Data Source=C:\Program Files\Microsoft Visual FoxPro 7\Samples\Data\testdata.dbc"; > strsql1 = "select * from customer"; > strsql2 = "select * from orders"; > > DataSet ds = new DataSet("testdata"); > ds.Tables.Add("customer"); > ds.Tables.Add("orders"); > > OleDbConnection conn = new OleDbConnection(strcon); > conn.Open(); > > OleDbDataAdapter daCustomer = new OleDbDataAdapter(strsql1, conn); > OleDbDataAdapter daOrders = new OleDbDataAdapter(strsql2, conn); > > daCustomer.Fill(ds.Tables["customer"]); > daOrders.Fill(ds.Tables["orders"]); > conn.Close(); > > DataRelation myRel = new DataRelation("CustomerOrders", > ds.Tables["customer"].Columns["cust_id"], > ds.Tables["orders"].Columns["cust_id"], > false); > > ds.Relations.Add(myRel); > > foreach (DataRow row in ds.Tables["customer"].Rows) > { > Console.WriteLine(row["cust_id"]); > DataRow[] aRows = row.GetChildRows(myRel); > for (int childs=0;childs<aRows.Length;childs++) > { > Console.WriteLine("\t{0}\t{1}", > aRows[childs]["order_id"], > aRows[childs].GetParentRow(myRel)["company"]); > } > } > } > } >} >>
>Metric VFP C# ># characters 330 1413 ># lines 12 51 >>