473,715 Members | 5,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fill a tree view with a stored procedure

I have a stored procedure that returns a dataset. I want this dataset to
fill a tree view.

Here is the Stored Procedure Query

SELECT Product.Product _#, Product.Part_Nu mber, Status.Status,
Traveler_Step.S tep, Station.Station _Name
FROM Product INNER JOIN
Traveler_Step ON Product.Travele r_Step_# =
Traveler_Step.T raveler_Step_# INNER JOIN
Station ON Traveler_Step.S tation_# = Station.Station _#
INNER JOIN
Status ON Product.Status_ # = Status.Status_#
WHERE (Station.Statio n_# = 8)
Here is a typical result

Product_# Part_Number Status Step
Station_Name
----------- -------------------- -------------------- ----------- --------------------
48 123789 Active 40 Hot Mill
231 U06107LG Active 20 Hot Mill
I would like the tree view master node to be Station Name, the first child
node to be the Part Number with an icon next to it indicating the status,
next child node under part_number the Step and Product_#.

So this is what I am after

HotMill
|
-----(Active icon) 123789
|
------40
|
------48

I understand I need hierarchical data, but the stored procedure only returns
one dataset. How can I do this?

Thanks.

John
Mar 1 '06 #1
2 4096
Hi John
Suppose you populate your dataTable and you are ready to fill your tree
using FillTree :

private void FillTree(DataTa ble table)
{
foreach (DataRow row in table.Rows)
AddRow(row);
}

private void AddRow(DataRow row)
{
TreeNode stationNode =
FindStationNode (row["Station_Na me"].ToString());
if (stationNode == null)
AddStationNode( row["Station_Na me"]);

AddToStation(st ationNode, row);
}

private void AddToStation(Tr eeNode stationNode, DataRow row)
{
TreeNode node = new TreeNode();
node.Text = row["Part_Numbe r"].ToString();
if (row["Status"].ToString() == "Active")
node.ImageIndex = 0;
else
node.ImageIndex = 1;
node.Nodes.Add( row["Step"].ToString());
node.Nodes.Add( row["Product_#"].ToString());

stationNode.Nod es.Add(node);
}

private void AddStationNode( string name)
{
treeView1.Nodes .Add(name);
}

private TreeNode FindStationNode (string p)
{
foreach (TreeNode node in treeView1.Nodes )
if (node.Text == p)
return node;
return null;
}

Best Regards,
A.Hadi

Mar 1 '06 #2
I'm sorry.I thought I am in C# group. (VB version) :
Private Sub FillTree(ByVal table As DataTable)

For Each row As DataRow In table.Rows
AddRow(row)
Next
End Sub

Private Sub AddRow(ByVal row As DataRow)

Dim stationNode As TreeNode =
FindStationNode (row("Station_N ame").ToString( ))
If stationNode Is Nothing Then
AddStationNode( row("Station_Na me"))
End If
AddToStation(st ationNode, row)
End Sub

Private Sub AddToStation(By Val stationNode As TreeNode, ByVal row
As DataRow)

Dim node As TreeNode = New TreeNode()
node.Text = row("Part_Numbe r").ToString ()
If (row("Status"). ToString() = "Active") Then
node.ImageIndex = 0
Else
node.ImageIndex = 1
node.Nodes.Add( row("Step").ToS tring())
node.Nodes.Add( row("Product_#" ).ToString())
End If

stationNode.Nod es.Add(node)
End Sub

Private Sub AddStationNode( ByVal name As String)

TreeView1.Nodes .Add(name)
End Sub

Private Function FindStationNode (ByVal name As String) As TreeNode

For Each node As treenode In treeView1.Nodes
If node.Text = name Then
Return node
End If
Next
Return Nothing
End Function

Thanks

Mar 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8100
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure creates a string of custom SQL statement and returns this string back to the main stored procedure. This SQL statements work fine on there own. The SQL returned from the sub stored procedure are returned fine. The datatype of the variable that...
10
5632
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures changed to be like:
1
2183
by: Bob Sparks | last post by:
I found this in a FAQ How can I locate the dependencies of an SQL procedure? A: The dependencies are stored in the package of the stored procedure. After creating a stored procedure, determine the name of the package. Then locate the dependencies under SYSCAT.PACKAGEDEP for the package. This seems un workable as the only way I have found to "determine the name of the package" is to scan through the
2
1848
by: Justin | last post by:
I am creating a web app for a client in VS.NET using ASP.NET with C#. I need to query three tables in a database using one parameter and display the results on the page. my question is should I use a Stored Procedure or view in SQL Server to get the data from multiple tables? What is the difference? and where can I find a some articles on write code to display the results of the SP or view? Thanks, Justin.
9
47204
by: Nikolay Petrov | last post by:
How to fill DataSet from stored procedure?
5
2298
by: moondaddy | last post by:
I have a website where cataloge pages are populated by calling a stored procedure on sql server. I use the sql data adapter's fill method to call this stored procedure and fill the dataset. about 6 to 15 times a day the server hangs and times out when this fill method is called. The SP is simple and uses very little resources (as tested using client statistics in query analyzer). Here's data from my error log which includes the...
10
13312
by: Rich | last post by:
I have a stored procedure on Sql Server2k. I can fill a data table which I can append to a dataset using an ADODB recordset object which gets populated from a command object that runs the sp. I was hoping to use a DataAdapter. But I think the data adapter only uses select statements. I could write the sp in my vb.net app, but the sp references UDF's I wrote in the Sql Sever. I will guess that I will need to stick with the ADODB recordset...
0
1606
by: negmat | last post by:
Does anyone know how exactly the sub-tree cost is calculated and whether it should be used as an indication of query/stored procedure performance? I used to think (although I could never find a single definitive source to state it clearly and precisely) that a sub-tree cost is some function of (reads + cpu time). However, my recent experience appears to challenge this belief. Namely, I have a few versions of a stored procedure, where each...
1
13225
by: apothecary | last post by:
Hello Newbie here. Is there a way of creating a VIEW...using a stored procedure. I am basically trying to create a view to return some data that I am getting using a stored procedure. I have created the procedure and when I execute this its working ok. The stored procedure uses a datefrom and dateTo which I have set up by
0
8821
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9103
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2118
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.