Re: Dumb question #102
From: Scott M. (s-mar_at_BADSPAMsnet.net)
Date: 02/09/04
- Next message: William \(Bill\) Vaughn: "Re: Am I wrong"
- Previous message: William \(Bill\) Vaughn: "Re: Database Decision"
- In reply to: Martin Robins: "Re: Dumb question #102"
- Next in thread: Martin Robins: "Re: Dumb question #102"
- Reply: Martin Robins: "Re: Dumb question #102"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 8 Feb 2004 21:42:42 -0500
Martin, I see what you are getting at and (IMHO), I wouldn't have set up the
data this way to begin with. In my "Accounts" table, I would have a record
like this:
MR1, Martin, OnHold, Bob
Where the field that contains the value "OnHold" is related to a record in
the "Status" table with a primary key of "OnHold", not "1". The field that
contains "Bob" is related to a record in the table "Controller", where there
is a record that has "Bob" as its primary key value, not "2".
The "OnHold" field value in the Accounts table is related to the "OnHold"
record in the Status table and the "Bob" field value in the Accounts table
is related to the "Bob" record in the Controller table. The data you want
is already in the Accounts table and there is no need to worry about how to
access it (the point of your post). What you get for your trouble is that
if someone were to try to delete the "Bob" record from Controllers or the
"OnHold" record from Status, referential integrity would prevent it (the
point of having relationships).
All the data you need would be in the Accounts table to begin with and you
just loop through that.
"Martin Robins" <martin - robins @ ntlworld dot com> wrote in message
news:%23GTj8Yp7DHA.2644@TK2MSFTNGP11.phx.gbl...
> But I do want the relations - I simply cannot work out how to access them
> from the related tables whilst looping through the main table.
>
> Here is a simple loop to read the main table; can somebody add in the
> missing line to get the related data, making the assumption that I have
> already set up the necessary relationships?
>
> foreach (DataRow dataRow in ds.Tables["Accounts"].Rows) {
> Console.WriteLine(dataRow["Reference"].ToString());
> Console.WriteLine( ??? ); // What goes here to display the Status.Text
> related to the Accounts.Reference just displayed?
> }
>
> Base on the previously supplied example data; I want to display
>
> MR1
> On Hold
> MR2
> Trading
> MR3
> On Hold
>
>
> This is the question I am asking; I can populate the tables, I can set up
> the relationships and I can loop through the main table sequentially
> displaying the content; I simply cannot display the related table data.
>
> Thanks.
>
>
>
> "Cor" <non@non.com> wrote in message
> news:%23DA2Xpo7DHA.2088@TK2MSFTNGP10.phx.gbl...
> > Hi Martin,
> >
> > If you do not want the relations, you can choose for the
datatable.select
> > and/or you can use the dataview.rowfilter or even a normal loop throught
> the
> > tables, it is on you how to use it.
> >
> > Cor
> >
> > > Sorry guys, everybody seems to be missing the question.
> > >
> > > I have a typed DataSet with multiple, related tables and the
> relationships
> > > set up. I want to loop through a table, and be able to pull out data
> from
> > > the related tables. For example (using the example tables I provided
> > > originally)
> > >
> > > Accounts MR1, Martin, 1, 2
> > > MR2, David, 2, 3
> > > MR3, Stephen, 1, 3
> > >
> > > Status 1, On Hold
> > > 2, Trading
> > > 3, Legal
> > >
> > > Controller 2, Bob
> > > 3, Terry
> > >
> > > I want to be able to loop through the Accounts table, pulling out:
> > >
> > > MR1, Martin, On Hold, Bob
> > > MR2, David, Trading, Terry
> > > MR3, Stephen, On Hold, Terry
> > >
> > > I want to do this programatically; how do I loop through the tables
> > > correctly to pull out this data?
> > > I can loop through the Accounts table without problem, [foreach
(DataRow
> > row
> > > in ds.Tables["Accounts"].Rows) {}], but how do I pull the related data
> > from
> > > Status and Controller for each row that I process?
> > >
> > > Cheers.
> > >
> > >
> >
> >
>
>
- Next message: William \(Bill\) Vaughn: "Re: Am I wrong"
- Previous message: William \(Bill\) Vaughn: "Re: Database Decision"
- In reply to: Martin Robins: "Re: Dumb question #102"
- Next in thread: Martin Robins: "Re: Dumb question #102"
- Reply: Martin Robins: "Re: Dumb question #102"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|