Problems with Combobox

  • Thread starter Thread starter mollyf
  • Start date Start date
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
 
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
 
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
 
Back
Top