Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Relations into a DataSet
Message
From
13/10/2006 10:09:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01161644
Message ID:
01161729
Views:
11
This message has been marked as a message which has helped to the initial question of the thread.
>Hya.
>
>Lets say that there are two tables in a DataSet, and both tables have a field with the same name, for instance, Address. Then I create a relation ...
>
>DataSet1.Relations.Add("Relation1", DataSet1.Tables(0).Columns("Column1"), DataSet1.Tables(1).Columns("Column1"), False)
>
>Once Relation1 is created, I need to reference that field with the same name in both tables:
>
>Relation1.Address
>
>Which Address will return ?
>
>When was it they said we were going to get VFP into .NET? :)
>Oh, sorry, it's late here, I'm already dreaming.
>
>Thanks.

Ivan,
I'm not sure that syntax would work. However referencing in parent or child over a relation is not only possible but more powefull in .Net IMHO (IOW I wish VFP imported those capabilities:).

Check Re: Easy in VFP !!! Thread #1032196 Message #1032287 for a sample. And here is another one sort of mimics your problem:
using System;
using System.Data;
using System.Data.OleDb;

namespace relationsample
{
    class Program
    {
        static void Main(string[] args)
        {
            string strCon = "Provider=VFPOLEDB;Data Source=" +
                @"C:\PROGRAM FILES\MICROSOFT VISUAL FOXPRO 9\SAMPLES\Data\testdata.dbc";
            string strParentSelect = "select cust_id, company as name from customer";
            string strChildSelect = "select c.cust_id," +
                " e.First_Name-e.Last_Name as name," +
                " o.order_net as orderTotal" +
                " from customer c" +
                " left join orders o on o.cust_id = c.cust_id" +
                " left join employee e on o.emp_id = e.emp_id";
            // represents a sample child table

            OleDbConnection cn = new OleDbConnection(strCon);
            OleDbDataAdapter daLeft = new OleDbDataAdapter(strParentSelect, cn);
            OleDbDataAdapter daRight = new OleDbDataAdapter(strChildSelect, cn);
            DataSet ds = new DataSet("mySample");
            daLeft.Fill(ds, "myParent");
            daRight.Fill(ds, "myChild");

            ds.Relations.Add("p2c",
                ds.Tables["myParent"].Columns["cust_id"],
                ds.Tables["myChild"].Columns["cust_id"], false);

            // add calculated columns to parent
            // that sums its children and order count
            ds.Tables["myParent"].Columns.Add("orderSum",
                typeof(double),
                "Sum(Child(p2c).orderTotal)");
            ds.Tables["myParent"].Columns.Add("orderCount",
                typeof(int),
                "Count(Child(p2c).orderTotal)");
            // add calculated column to child
            // that shows its parent's name
            ds.Tables["myChild"].Columns.Add("myParentName",
                typeof(string),
                "Parent(p2c).Name");
                       

            foreach (DataRow row in ds.Tables["myParent"].Rows)
            {
                Console.WriteLine("Parent:{0}\t\tTotal {1} in {2} orders",
                    row["name"],
                    row["orderSum"],
                    row["orderCount"]);
                Console.WriteLine("\tDetails");
                foreach (DataRow child in row.GetChildRows("p2c"))
                {
                    Console.WriteLine("\tmyChild name:{0}\tOrder total:{1}",
                        child["name"],child["orderTotal"]);
                }
            }
        }
    }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform