Solved

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

Posted on 2006-06-30
4
321 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 125 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

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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