Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Custom selection from dataset

Posted on 2004-08-06
3
Medium Priority
?
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 1500 total points
ID: 11740722
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

609 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