A
Andreas Leitner
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>
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>