PC Review


Reply
Thread Tools Rate Thread

dataset for tree structure?

 
 
Andreas Leitner
Guest
Posts: n/a
 
      23rd Jul 2003
Hi,

how can I (can I at all?) model trees with data sets?

Given I have the following db-table:

---
Table Folder:
FolderId (Primary Key)
Name
ParentFolderId (Foreign Key to Folder/FolderId, Nullable)
---

This is a simple tree, just like a directory structure on a file system
is (it's even simpler, there are no files

Here is my try:

---
DataSet result = new DataSet ("FolderTree");
SqlDataAdapter adapter = new SqlDataAdapter("select * from [Folder]",
connection);
adapter.Fill(result, "Folder");

result.EnforceConstraints = false;

DataRelation rel = result.Relations.Add("FolderContainsFolder",
result.Tables["Folder"].Columns["FolderId"],
result.Tables["Folder"].Columns["ParentFolderId"]);
rel.Nested = true;

result.EnforceConstraints = true;

result.WriteXml ("c:\\folder_tree.xml");
---

But when I try to run this code, I get an exception saying that a
circular references has been found.

I would like to get an XML representation like this:
---
<FolderTree>
<Folder>
<FolderId>1</FolderId>
<Name>Root</Name>

<Folder>
<FolderId>2</FolderId>
<Name>A</Name>
<ParentFolderId>1</ParentFolderId>
</Folder>
<Folder>
<FolderId>3</FolderId>
<Name>B</Name>
<ParentFolderId>1</ParentFolderId>
</Folder>
<Folder>
<FolderId>4</FolderId>
<Name>C</Name>
<ParentFolderId>1</ParentFolderId>
</Folder>
</Folder>
</FolderTree>
---

many thanks in advance,
Andreas

 
Reply With Quote
 
 
 
 
Andreas Leitner
Guest
Posts: n/a
 
      24th Jul 2003
David Browne wrote:
> This is an "unnested" or flat xml representation of the data.
>
> For this just set
>
> rel.Nested = false;
>
> David


Hi David,

thank you very much for answering. I know of that way. Sorry my original
post was not clear on this point. I want users to modify the resulting
XML file (and then reimport it to the db). A flat XML representation is
just too confusing for users. Isn't there any way to output a nested
version?

If nothing else helps, what do you (or others) think about
postprocessing the flat XML with an XSLT sheet? The sheet would
transform the flat file into a nested one (not sure exactly how complex
this will turn out to be , then the user modifies the nested XML file.
Before importing I would retransformate it into a non-nested XML file.

many thanks in advance,
Andreas


 
Reply With Quote
 
Andreas Leitner
Guest
Posts: n/a
 
      24th Jul 2003
Looks like i was too tired yesterday to see the obvious.
It actually works the way I described it initially, but my table
had indeed a circular reference... (which means it doesnt represent a
tree anymore of course). After removing the circular reference all
worked as expected...


regards,
Andreas

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tree Structure in VBA =?Utf-8?B?SmFjaw==?= Microsoft Outlook VBA Programming 1 22nd Jul 2006 04:41 PM
tree structure. is it possible? =?Utf-8?B?RGVmYXVsdA==?= Microsoft Access 2 20th Apr 2005 09:51 PM
Tree Structure ExcelMonkey Microsoft Excel Programming 4 25th Feb 2005 02:07 AM
Tree structure Rakesh Microsoft C# .NET 4 13th Jan 2004 08:17 PM
tree structure? Adalbert Microsoft Dot NET 1 2nd Jul 2003 06:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:03 AM.