473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems with Combobox

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)("D escription"))
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

Nov 21 '05 #1
2 1003
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
--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
<mo****@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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)("D escription"))
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

Nov 21 '05 #2
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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
0
by: jac | last post by:
Hey, this.CmbDataSource = SoortKwijtingList.Items; // Arraylist this.Cmb.DisplayMember = "Omschrijving"; this.Cmb.ValueMember = "Id"; this.Cmb.SelectedIndex = -1; (short description : I...
5
by: ross kerr | last post by:
Hi All, I am extending the combobox to create a control that selects an item based on the text the user is typing into the text area of the control. I have an issue that occurs only when i...
4
by: MadCrazyNewbie | last post by:
Hey Group, Just another quick question: I have the following bit of code: Private Sub cboPasswordListsDepartment_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)...
10
by: Richard | last post by:
I have created a form which sets up a dataview. The form views one record at a time using a currencymanager. This works fine. All my text boxes bind. However I have a combo box which gets its...
3
by: DeWittds | last post by:
I have a combo box that I can not get to sort correctly. I fill the combobox with a customer id and name ( combined) have set the combobox.sorted = true I saw one Idea here about turning the...
2
by: Horst JENS | last post by:
Hi group, have problems with combobox-control in a form (access 2003). I added VBA-Code to on-Change event of the control. If the user choose an value from the control, the filter of the form...
5
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, I'm using a combobox in DropDown style. It shows the time in hours for a proces. In the drop down list I've put in some values like 15 min 30 min 45 min 1 h 2h
0
by: theleshie | last post by:
Hi, I am creating an application which dynamically creates forms depending on the information held in a dataset (which also includes the data the application itself uses). As part of dynamically...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.