C
C P
I'm just getting into ADO.NET and C#, and am playing with some options to
move my old Win32 app to this new platform.
My app displays a questionairre where the questions are organized in a
hierarchy (much like a directory structure). In my current app, everything
is fixed at 4 levels, and is stored in 4 tables. (i.e. the actual questions
are always at 'level 4', and levels 1, 2 and 3 group the questions).
I was hoping to be more dynamic and store this in a single table. I've set
up a table where each record can reference a parent. Every record has a
recId field that is unique. Each record optionally fills a parentRecId
field that points to it's parent, or is null (if this is a root). ...it's a
basic tree structure.
I was hoping with XML etc. and ADO.NET, I'd be able to construct this
automatically into a hierarchy from the single flat table. I've tried using
a data relation to link the parentRecId fields to the recID fields.
However, the best I can get is to have the parent records, and one level of
children, but I can't get the grandchildren and greatgrandchildren etc. to
happen automatically.
I've played around with creating a schema, but I don't really know what I'm
doing here. Is what I want to do even possible (without a lot of manual
work)? Maybe there's a SQL FOR XML statement that could build a
hierarchical XML file from a single flat table? I suppose I could build
some recursive functions to build the XML manually, but I'm hoping that
VS.NET/XML/ADO.NET already supports this.
Thanks,
Chris
move my old Win32 app to this new platform.
My app displays a questionairre where the questions are organized in a
hierarchy (much like a directory structure). In my current app, everything
is fixed at 4 levels, and is stored in 4 tables. (i.e. the actual questions
are always at 'level 4', and levels 1, 2 and 3 group the questions).
I was hoping to be more dynamic and store this in a single table. I've set
up a table where each record can reference a parent. Every record has a
recId field that is unique. Each record optionally fills a parentRecId
field that points to it's parent, or is null (if this is a root). ...it's a
basic tree structure.
I was hoping with XML etc. and ADO.NET, I'd be able to construct this
automatically into a hierarchy from the single flat table. I've tried using
a data relation to link the parentRecId fields to the recID fields.
However, the best I can get is to have the parent records, and one level of
children, but I can't get the grandchildren and greatgrandchildren etc. to
happen automatically.
I've played around with creating a schema, but I don't really know what I'm
doing here. Is what I want to do even possible (without a lot of manual
work)? Maybe there's a SQL FOR XML statement that could build a
hierarchical XML file from a single flat table? I suppose I could build
some recursive functions to build the XML manually, but I'm hoping that
VS.NET/XML/ADO.NET already supports this.
Thanks,
Chris