Problems with Combobox

M

mollyf

Hello everyone--

I've tried many of the things I've found searching the newsgroups in
trying to store 2 fields to a combobox and use displaymember and
valuemember but nothing is working. Here is my code:

Dim strSQL As String
Dim dataAdapt As New OleDbDataAdapter
Dim cmd As New OleDbCommand
Dim rst As New DataSet
Dim x As Integer

strSQL = _
"SELECT RaceID, Description " & _
"FROM tblRace"

cmd.Connection = cnDB
cmd.CommandType = CommandType.Text
cmd.CommandText = strSQL
dataAdapt.SelectCommand = cmd

cboRace.DataSource = rst.Tables("tblRace")
cboRace.DisplayMember = "Description"
cboRace.ValueMember = "RaceID"
dataAdapt.Fill(rst, "tblRace")

Nothing shows up in my combobox when I use the above code. If I use
the following code, I do get my combobox populated:

For x = 0 To rst.Tables("tblRace").Rows.Count - 1

cboRace.Items.Add(rst.Tables("tblRace").Rows(x)("Description"))
Next

This isn't what I want though because I need to capture the RaceID that
is selected. Any ideas of what I'm doing wrong?
Thanks.

Molly J. Fagan
Oklahoma Foundation for Medical Quality
 
W

W.G. Ryan eMVP

Check the Debug.Assert(rst, "tblRace")rst.Tables("tblRace").Rows.Count > 1
and make sure you have the names spelled corredtly for the displaymember and
valuemember.

Also, put the fill first before setting the datasource and DisplayMember and
Valuemember
 
M

mollyf

I've tried putting the fill before setting the datasource (saw many
examples where it was put afte), etc. but I still get nothing. There
are records in the table and all of the field names are spelled
correctly.


Molly J. Fagan
Oklahoma Foundation for Medical Quality
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top