populate a top tree view with a query data

Dear experts
how do i populate a treeview with a query

cn.Open()
        Dim nusa10 As String = "SELECT distinct proyecto from jsmtmp1"
        Dim cmd10 As New OleDbCommand(nusa10, cn)
        cmd10.ExecuteScalar()
        cn.Close()


i want to populate with the result of that query
tsm
edo
ErnestoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
The  ExecuteScalar method will, "Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored." from Microsoft documentation. So there is only one value coming back from the query, not enough data to fill a TreeView.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ErnestoAuthor Commented:
Fernando
Do you have a code for explain?
Regards
Fernando SotoRetiredCommented:
Your query,
 Dim nusa10 As String = "SELECT distinct proyecto from jsmtmp1"

Open in new window

when executed with this statement,
cmd10.ExecuteScalar()

Open in new window

will only return one single value which in this case you are not storing it. To capture the return value you would do something like this,
Dim returnVal = cmd10.ExecuteScalar()

Open in new window

ErnestoAuthor Commented:
yes fernando, but i need the statements for the treeview node, do you have an specific example for populate the top of the tree with the query?
regards
Fernando SotoRetiredCommented:
Hi edo60;

To assign the value returned from the query you can do the following
Dim returnVal = cmd10.ExecuteScalar()
Dim tn As New TreeNode(returnVal)
TreeView1.Nodes.Add(tn)

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.