|
-
Apr 3rd, 2002, 11:18 AM
#1
Thread Starter
New Member
Just starting VB.NET, adding from DataSet to Multi Listbox
Good morning all. OK here is the situation. I am just starting to learn VB.NET and I want to take a SQL connection or a table and populate a multi-column listbox. Here is the code I have so far
Dim selectCMD As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT * FROM tblDeals", myConnection)
Dim custDA As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter()
Dim custDS As DataSet = New DataSet()
Dim pRow As DataRow
selectCMD.CommandTimeout = 60
custDA.SelectCommand = selectCMD
custDA.Fill(custDS, "tblDeals")
Me.lstDeals.Items.Clear()
Me.lstDeals.MultiColumn = True
Me.lstDeals.BeginUpdate()
For Each pRow In custDS.Tables("tblDeals").Rows
' is it done this way???
Me.lstDeals.Items.Add(????)
Next
If VB 6 I know what to do, however how does the new VB.NET handle this. Any help on this would be great.
-
Apr 5th, 2002, 03:17 AM
#2
New Member
We are all learning vb.net here!
Anyway, I think you go too far with your code, if you want to do the job yoprself rather than using .Net's pomt and click facilities then all you need to do it to set the proerties of the listbox thus:
lstDeals.DataSource = custDS
lstDeals.DisplayMember = "tblDeals.NameofSomeColumn"
listDeals.ValueMember = "tblDeals.NameofSomeOtherColumn"
Then when you fill the data set the list box will be populated automatically.
From what I can work out it is only if you use the DaraReader object do you have to worry about looping and adding items to listboxex, combos etc.
Hope this helps
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|