Home All Groups Group Topic Archive Search About

ADO and parent/child/grandchildren

Author
11 Jan 2006 10:58 PM
Jeremiah Harbottle
Hi,

Using VC to write a small app that displays data extracted from a database
into a typed DataSet. That all works fine.

I have three tables - Parent, Child, and then each record in the Child table
also has children.

I want three grids - one for each table:

A. Parent (ParentID is key)
B. Child  (ChildID is key, FK to ParentID)
C. GrandChild (GCID is key, FK to ChildID)

So, when the user selects a parent, the child grid shows the correct
records. Subsequently, selecting a child row should show the grandchildren
records for that row.

I've set up all the datarelations correctly and used the DataSource,
DataMember on the grid.

GridA - DataSource = myDataset
             DataMember = ParentTable
GridB - DataSource = myDataSet
            DataMember = ParentChildRelation
GridB - Datasource = myDataSet
            DataMember = myChildGCRelation

Selecting a record in A causes B to only shows those with the correct FK.
Brilliant. Adding a new record fills in the FK column with the correct
value. Splendid!

However, it doesn't work with the Child/Grandchild tables? The GrandChild
grid always shows the same record...

Can .Net handle this? Am I doing something wrong?

Regards,
JH

Author
17 Jan 2006 12:49 AM
Robbe Morris [C# MVP]
Why do you have a grandchild relationship?

You should just have a parent and a child.

Each child can be a parent and so and
son on.

You would use recursion to traverse
the entire hierarchy of your DataSet.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp





Show quote
"Jeremiah Harbottle" <nik***@REMOVETHIS.nildram.REMOVETHIS.co.uk> wrote in
message news:xsadnU1F5uA-EFjenZ2dnUVZ8t2dnZ2d@pipex.net...
> Hi,
>
> Using VC to write a small app that displays data extracted from a database
> into a typed DataSet. That all works fine.
>
> I have three tables - Parent, Child, and then each record in the Child
> table
> also has children.
>
> I want three grids - one for each table:
>
> A. Parent (ParentID is key)
> B. Child  (ChildID is key, FK to ParentID)
> C. GrandChild (GCID is key, FK to ChildID)
>
> So, when the user selects a parent, the child grid shows the correct
> records. Subsequently, selecting a child row should show the grandchildren
> records for that row.
>
> I've set up all the datarelations correctly and used the DataSource,
> DataMember on the grid.
>
> GridA - DataSource = myDataset
>             DataMember = ParentTable
> GridB - DataSource = myDataSet
>            DataMember = ParentChildRelation
> GridB - Datasource = myDataSet
>            DataMember = myChildGCRelation
>
> Selecting a record in A causes B to only shows those with the correct FK.
> Brilliant. Adding a new record fills in the FK column with the correct
> value. Splendid!
>
> However, it doesn't work with the Child/Grandchild tables? The GrandChild
> grid always shows the same record...
>
> Can .Net handle this? Am I doing something wrong?
>
> Regards,
> JH
>
>
>
>

AddThis Social Bookmark Button