Question Selecting two values from combo box to return a price

chrismid259

Member
Joined
Feb 9, 2011
Messages
6
Programming Experience
Beginner
Hi all,
I'm currently creating a ticket ordering system. I'm having some slight trouble getting one of the key elements of the application to work mainly because I'm not sure where to start with it.


I currently have a form with two combo boxes (one for the origin of the journey and one for the destination). The idea is that the customer tells the employee over the phone where their journey begins and ends. They will also select a date of travel - but the date of travel doesn't really matter to much at this time.


Once a to and from is selecting from each combo box, the price will be shown in a label on the same form. On a side note, because of special conditions that I must implement into the application, the price is actually only calculated from what is selected in ComboBox2 (the destination).


I have the destination and prices information in an Access database table and my database is already linked to my application using a data connection. The table itself in Access has no relationships but other tables in the database do.



Could anyone please help me with trying to get to price to display when the two values in the combo boxes are selected?
 
If you are really calculating a ticket price on destination alone then I can only assume that this is a homework assignment and not a real application. It's considered polite to explain such things, because otherwise you are basically tricking us, intentionally or not, into doing your homework for you. We can certainly help, homework or not, but the purpose of the application should also dictate the type of help provided. I, for one, generally avoid posting code for homework questions. I'm happy to provide guidance but it's really for people to write their own code for homework questions.

Anyway, what you're basically saying is that you need to query a database to get a price from a table where a destination equals a particular value, right? How much do you know about data access? What have you implemented already? For instance, the advice provided will differ depending on what you already have in place. In general, you need to connect to your database and execute a query with a parameter in the WHERE clause to filter on destination.
 
Hi,
Thank you for your reply. Yes, it would be fair to say that this is a homework question. I have completed the majority of my application but I'm having trouble with exactly how to implement this final part of the application.

I'm a beginner when it comes to data access although I do have some data connections, data sets and queries set up in my application. So I am familiar with them.

Up to now I've implemented onto the form; 2 combo boxes (one contains the origin station, the other contains the destination), I also have a label that will show the price. The only other thing I have is a ticket prices dataset which only refers to the table in the database that holds the destination stations and the prices for each. In the database itself, this table has no relationships.
 
So, you have a typed DataSet in your project, correct? If so, you should add a query. You do so in the designer, much like adding a control to a form. You can add new queries to existing TableAdapters that allow you to fill existing DataTables in different ways, e.g. using filters, or you can add a new TableAdapter that doesn't rely on any particular DataTable schema. In your case, you should go the latter. Create a query that takes a parameter value containing a destination name and returns the corresponding price. You can then call the appropriate method on the appropriate TableAdapter to execute that query.

For some reading on the subject:

TableAdapters
 
Back
Top