Results 1 to 4 of 4

Thread: [RESOLVED] ComboBox w/ Datareader

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    39

    Resolved [RESOLVED] ComboBox w/ Datareader

    I'm using a DataReader to populate a combo box. Its simple enough -
    VB Code:
    1. Dim clsDB As New DBClass
    2.         Dim dr As SqlDataReader
    3.         clsDB.ConnString = ConfigurationSettings.AppSettings("ConnString")
    4.         clsDB.SPName = "mmu_Select_ChangeCodes"
    5.         dr = clsDB.GetDR
    6.         Do While dr.Read()
    7.             Me.cboChangeCode.Items.Add(dr.Item("change_code_desc"))
    8.         Loop
    9.         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:
    1. Me.cboChangeCode.DataSource = dr
    2.         Me.cboChangeCode.DisplayMember = "change_code_desc"
    3.         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.....

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    39

    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.

  4. #4
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: ComboBox w/ Datareader

    Quote 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
  •  



Click Here to Expand Forum to Full Width