Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

How do I populate a combo box with datareader where I have a value to display and a value to be read

I am using a datareader to load two fields:

Region code : I need to use the code to save it later in another table
Region Name: I need to display the region name in the combo box

I'm trying to use "tag" to save the regioncode which is my first field...It's not working
please help
thanks
dr = datareader <-
cboregioncode <- combo box
 
       While dr.Read()
            cboRegionCode.Items.Add(dr(1))
            cboRegionCode.Tag = dr(0)
        End While
        dr = Nothing

Open in new window

0
pachecosita
Asked:
pachecosita
1 Solution
 
Chad SmithSoftware EngineerCommented:

cboRegionCode.Items.Add(New ListItem(dr(1), dr(0)))
0
 
jpaulinoCommented:
If you have a datasource like a SqlDataReader, why don't you do something like this:

Me.cboregioncode.DataSource = dr
Me.cboregioncode.DisplayMember = "Region Name (Field Name)"
Me.cboregioncode.ValueMember = "Region Code (Field Name)"
0
 
pachecositaAuthor Commented:
I found out the best one to use is Dataset!
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now