|
-
Oct 20th, 2005, 07:11 PM
#1
Thread Starter
Member
[RESOLVED] ComboBox w/ Datareader
I'm using a DataReader to populate a combo box. Its simple enough -
VB Code:
Dim clsDB As New DBClass
Dim dr As SqlDataReader
clsDB.ConnString = ConfigurationSettings.AppSettings("ConnString")
clsDB.SPName = "mmu_Select_ChangeCodes"
dr = clsDB.GetDR
Do While dr.Read()
Me.cboChangeCode.Items.Add(dr.Item("change_code_desc"))
Loop
dr.Close()
The problem with doing it this way is I cant set a Value member.
If I bind the Datareader to the control via
VB Code:
Me.cboChangeCode.DataSource = dr
Me.cboChangeCode.DisplayMember = "change_code_desc"
Me.cboChangeCode.ValueMember = "change_code"
I get the following error, "Additional information: Complex DataBinding accepts as a data source either an IList or an IListSource"
The goal i need is to have index value and a display value on each combo box.
This was so much simpler in vb6.....
-
Oct 20th, 2005, 07:33 PM
#2
Re: ComboBox w/ Datareader
Hello welcome to the forum!
When binding a data in combobox use a datasource its either an array/arraylist or dataset/datatable. You could use a dataadapter then fill the data to your datatable then you could bind the datatable to your combobox. Search here and surely you could find a lot of it.
-
Oct 21st, 2005, 01:33 AM
#3
Thread Starter
Member
Re: ComboBox w/ Datareader
ok, I changed the datareader to a datatable and that did what I needed to do.
But i'm still not a fan of databinding. Perhaps its because I did a lot of complex ASP/VBScript pages in the past so I was used to dumping recordsets into arrays. I prefer using Datareaders for most everything because there fast and simple, but how can I set a displaymember and valuemember of a combo box, especially if I just to a read through a DR and add an item?
Additionally, what is the difference between a DataTable and DataSet? I tried doing this with a Dataset and the valuemember wouldn't bind.
-
Oct 21st, 2005, 01:54 AM
#4
Hyperactive Member
Re: ComboBox w/ Datareader
 Originally Posted by jdaustin
Additionally, what is the difference between a DataTable and DataSet? I tried doing this with a Dataset and the valuemember wouldn't bind.
A DataSet is a representation of collection of Databases objects including tables of relational databases scheme. It contains collection of Tables, Relations , constraints...
I've read that here
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
|