By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,490 Members | 1,328 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,490 IT Pros & Developers. It's quick & easy.

Pull data from a database to fill combo box.

P: n/a
I have a program setup to pull data from a database. My database table has
things such as (category, Item, price, etc.) In my program I want to have
multiple list boxes that will have a pull down list of different categories.

The category is stored as a number and the item is stored as a string. Also
once the item is picked from the list I would also like to extract the price
corresponding to the chosen item.

This program will be to custom build a computer. So for example. I want one
combo box to have a list of Motherboards(category 3) to choose from and then
once the board is chosen show the price of it next to it. Then below that I
want another combobox that will have a list of Processors(category 4) and
then show the price of that. I would like it to show this for all the
categories out of the database.

How would I go about doing something like
this. Thanks for your help!
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
At the risk of telling you some things you may already know, here goes...

I take it this is for a Windows form, but I am throwing in information about
Webforms, just in case.

On your Windows form you have ComboBoxes, ComboBox1, 2, etc, and a
corresponding TextBoxes, TextBox1, 2, etc.

In a Database table named Items you would have Fields: Category, Item, Price.
In the Form Load event, you would create a DataTable for each ComboBox:
Select * From Items WHERE Category = 1"
Select * From Items WHERE Category = 2"
etc
Use a Command object and a Connection to create the Datatables:
DT1, DT2, etc
For a dropdown box on a Windows form, use the ComboBox.
(For a Webform, use the DropDownList)

In the form Load event, set the Datasource property of each Combo or DDL to
the corresponding Datatable. Then, for the Combo, set the DisplayMember
property to the name of the field you want to display, i.e. Item.
(For a Webform DDL, set DataTextField to same.)
When using a Webform, in addition to setting the Datasource of the DDL, you
must call the DataBind method.

To put the price in the corresponding textbox:
In the SelectedIndexChanged event for the ComboBox (automatically created if
you double click the Combo in design mode), add the following code:

TextBox1.text = DT1.rows(ComboBox1.SelectedIndex).item("Price").to String

For a WebForm the event and code are essentially the same. You would set
AutoPostBack = True for each DDL in the Webform, in order for the user to see
the price upon selection of the item in the list.

www.charlesfarriersoftware.com

"Jeremy Dillinger" wrote:
I have a program setup to pull data from a database. My database table has
things such as (category, Item, price, etc.) In my program I want to have
multiple list boxes that will have a pull down list of different categories.

The category is stored as a number and the item is stored as a string. Also
once the item is picked from the list I would also like to extract the price
corresponding to the chosen item.

This program will be to custom build a computer. So for example. I want one
combo box to have a list of Motherboards(category 3) to choose from and then
once the board is chosen show the price of it next to it. Then below that I
want another combobox that will have a list of Processors(category 4) and
then show the price of that. I would like it to show this for all the
categories out of the database.

How would I go about doing something like
this. Thanks for your help!

Nov 21 '05 #2

P: n/a
Jerremy,

From your message I understood that you have one table in your database with
parts.

You can take all the columns needed as one datatable in memory or only to
take the itemnumbers, itemnames and category and than take another approach

The first is the most simple, however depending when there is as well
information as price and stock information in my opinion not the best one.

However that was not directly the question. When it is only about the
question, would I create from the datatable that you created with all
categories as much dataviews as there are comboboxes, where I would use
everytime the same table however with each time another rowfiltre what is
the category.

Those dataviews are the datasources for your comboboxes, probably the
itemnames the displaymembers and the itemnumbers the valuemembers.

This is very simple to do.

I hope this helps

Cor

"Jeremy Dillinger" <je*****@hotmail.com>
I have a program setup to pull data from a database. My database table has
things such as (category, Item, price, etc.) In my program I want to have
multiple list boxes that will have a pull down list of different
categories.

The category is stored as a number and the item is stored as a string.
Also
once the item is picked from the list I would also like to extract the
price
corresponding to the chosen item.

This program will be to custom build a computer. So for example. I want
one
combo box to have a list of Motherboards(category 3) to choose from and
then
once the board is chosen show the price of it next to it. Then below that
I
want another combobox that will have a list of Processors(category 4) and
then show the price of that. I would like it to show this for all the
categories out of the database.

How would I go about doing something like
this. Thanks for your help!

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.