Solved

Custom selection from dataset

Posted on 2004-08-06
3
232 Views
Last Modified: 2010-04-15
Hi Experts,

I generate a dataset with 3 column: PathId, ParentPathId, Path.

Example:
PathId                            ParentPathId                      Path
1                                   null                                    path1
2                                   1                                       path2
3                                   2                                       path3
4                                   2                                       path4
5                                   null                                    path5
6                                   5                                       path6

What I want to get is those paths:
path1
path1/path2
path1/path2/path3
path1/path2/path4
path5
path5/path6

Thanks in advance to help me to retrieve those paths.
0
Comment
Question by:noulouk
3 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
Comment Utility
you are going to need to make a recursive function in order to get that, no compiler in front of me but this should be close.

public string GetPath(int ParentId) {
    DataView dv = new DataView(ds.Tables["whatever"]);
    dv.RowFilter = "PathId = " + ParentId;
    if(dv.Rows.Count == 1) {
          return dv.Rows[0].Item["Path"].ToString() + "/" + GetPath(dv.Rows[0].Item["PathId"];
    } else if(dv.Rows.Count > 1) {
          throw new System.Exception("More than one child directory found for " + ParentId);
    }
}

then to build all ...

public StringCollection GetAllPaths() {
      StringCollection sc = new StringCollection();
      DataView dv =  new DataView(ds.Tables["whatever"]);
      dv.RowFilter = "ParentPathId = null";
      foreach(DataRowView dr in dv.Rows) {
             sc.Add(GetPath((int) dr["PathId"]));
      }
}
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now