May 4th, 2011, 04:00 PM
Using an object property in an SQL query
Can I use an object property (such as the Text value from a comboBox) in an SQL query so that the query results will be dependent upon the user's choice of said comboBox?
I have a makeComboBox with 5 car manufacturers. When the user chooses one, it enables modelComboBox, which is data bound to a table from a database. The table is called Models, and consists of 30 random car models, with a text field called Make that specifies which of the 5 manufacturers it came from. I want to populate modelComboBox with models from the Models table, but only those whose Make is the same as the one chosen in makeComboBox. I added a query called FillByMake with this SQL SELECT statement using the TableAdapter Query Configuration Wizard:
I added these lines to the makeComboBox_SelectedItemChanged event code:
SELECT Model FROM Models WHERE Make = makeComboBox.Text
It compiles but before it loads the form it gives me an unhandled OleDbException: "No value given for one or more required parameters." Can anyone help me by telling what I'm doing wrong and how to do it correctly?
modelComboBox.Enabled = true;
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!