Question Combo Box Fill

spaul

Member
Joined
Jul 2, 2008
Messages
10
Programming Experience
Beginner
I'm new to programming and I'm trying to put together an application that accesses a dataset from an access database. At this point the full dataset is brought into the program through OleDB. What I would like to do is to populate a combo box with all of the unique values in one of the fields. Any direction would be greatly appreciated.
 
Maybe you can use a SQL Query to populate the DataSet binded to the ComboBox. Something like:

SELECT DISTINCT ColumnName FROM TableName;
 
Thanks a lot for the reply!

In using the sql query, should I be getting the unique values from the access database, or from the dataset already loaded in the program?
 
Sorry... what I mean is that I have already brought the full dataset into my application using a sql statement. This dataset is an exact replica of the table in Access. To populate a combo box in my application with unique values from one of the fields, should I be getting these values from the original access table or from the filled dataset in my application.

Thanks again.
 
Just checking, that youre not trying to make a DataSet behave like a database i.e. youre not downloading your entire Access database into your dataset are you? DS are for temporary data storage only..

Now, to answer your Q, no.. youre better off defining a separate table, with all the permissible values.

Here's a well worn example:


tblPerson
lutSalutation

lut = Look Up Table, it contains:
1, Mr
2, Mrs
3, Miss

Now your tblPerson has a SalutationID for every person, that contains:
1
3
2
1
3
1
2
1

etc..

Its not possible for someone to type "Hello" in this because its a combo box whose source is lutSalutation.. You can enforce this with an FK constraint/relation
 
Great thanks a lot for the help! I now have the dataset of unique values being accessed by the program. I just can't seem to figure out how to databind this dataset to the combobox. Sorry for these very basic questions.
Thanks again.
 
cbo.DataSoucce = mydataset.lutSalutation
cbo.displayMember = "SalutationColumn"
cbo.ValueMember = "SalutationID"
 

Latest posts

Back
Top