Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamically add nodes to treeview from query pulling data from MS Access

Posted on 2006-06-30
4
Medium Priority
?
345 Views
Last Modified: 2010-05-18
I am using vb 2003 and MS Access 2000.

I need to, when a button is clicked, run a query to pull data from an Access table and populate a treeview with those values.

I already have the dataset working (I can go into preview data). The returned data is system hostnames and is called "hostname".

I would like the treeview to look like

-Server1
-Server2
-Server3
.....

I hope to reuse this type of thing if I could figure out how to add a node to a treeview as a result of a query.

Help!
0
Comment
Question by:edrz01
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 17019636
Hi edrz01,

See an article I wrote in April 2006 at http://emoreau.s2i.com/

Cheers!
0
 

Author Comment

by:edrz01
ID: 17019776
Eric,

Thanks for the response. I looked at your code and tried to incorporate it into mine but I am getting an error.

This is my code snippet:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ds As New DataSet
        Me.OdbcDataAdapter1.Fill(ds, "HostName")

        With tvServers
            .BeginUpdate()
            .Nodes.Clear()
            For Each drCat As DataRow In DsServerList1.Tables("hostname").Rows        <<<<<<< Error here
                Dim nodParent As TreeNode
                nodParent = tvServers.Nodes.Add(drCat.Item("hostName").ToString)
            Next drCat
            .ExpandAll()
            .EndUpdate()
            .Nodes(0).EnsureVisible()
        End With
    End Sub
----------------------------

The error I am getting in on the line indicated above by the <<<<<

An unhandled exception of type 'System.NullReferenceException' occurred

Any thoughts?
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 17019831
isn't your dataset called ds ?

Change this line:
For Each drCat As DataRow In DsServerList1.Tables("hostname").Rows        

for that one:
For Each drCat As DataRow In ds.Tables("hostname").Rows        
0
 

Author Comment

by:edrz01
ID: 17019858
Well, so it is. My oversight! You are a genius. Thank you, thank you, thank you - it worked!

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

879 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