472,800 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Pull data from a database to fill combo box.

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
2 6885
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Frazer | last post by:
hi i have a combo box which i populate with all tables from northwind database and when the user selects an item from the combo, i want to populate the datagrid with data from that table. ...
3
by: Snake | last post by:
I have a vb .net program which fills a data grid upon form load from an acccess database. This works great. Now, I have to add a combo box and use it to alter the underlying sql statement and...
1
by: Stephanie Wright | last post by:
I'm having a probem with my 3rd and 4th boxes not showing the correct data to pick. My database is normalized and I have Me! statements for each combo box in the After Update but something is...
4
by: Bill Hesson | last post by:
I am writing a database that handles all of the information for courses offered at a school. Each course id is unique based on school year id and course id. I need to duplicate the course names,...
20
by: MadCrazyNewbie | last post by:
Hey group, I keep getting the following error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll Additional information: There is no row at...
0
by: Gian Paolo | last post by:
this is something really i can't find a reason. I have a form with a tabcontrol with tree pages, in the second page there is a Data GRid View. Plus i have a class. When i open the form i...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
4
by: sparks | last post by:
We have a new project here, one that I have never tried maybe its easy I don't know yet. We have people that have records dating back over 5 yrs on a sql server. We have to build an access 2003...
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.