Question How to display data related to a combo box Selection

viper5646

Active member
Joined
Jan 20, 2009
Messages
38
Location
Canada
Programming Experience
Beginner
lets see if I can explain my self. I have 2 fields in the country the country table "CountryName & Countrycoed" .
My question is how to display the Contrycoed in a textbox after selecting the country in a combobox. For example if I select Canada in the combo
I would like CND to be displayed in the textbox. This is the SQL I have to load the combobox

Thank you

VB.NET:
comType.CommandText = String.Format("select CountryName,Countrycoed from Country ")
 
Hi thank you for your reply.
But I get an expression expected on (&) that is at the end of the SQL.
I have tried this SQL in diffrent way's but I can't get it to work.
VB.NET:
 countrycmd.CommandText = "SELECT Countrycode FROM country WHERE countryName = '" & cmbType.SelectedItem & '"CODE]
 
Upssss ... my bad. Please try this (the single quote should be from outside)
VB.NET:
countrycmd.CommandText = "SELECT Countrycode FROM country WHERE countryName = '" & cmbType.SelectedItem & [COLOR=darkgreen]"[/COLOR][COLOR=red]'[/COLOR]"

:):):) Thank you Kulrom you came through it works :):):)
 
Perhaps Im missing something here but is there even a need to query the database for this answer? Assuming that your are filling your combobox with two columns of info; DisplayMember being the country name that is seen by the user and ValueMember which is the items value in this case the hidden country code.

When the user selects the item saying "Canada" in the combobox. Calling: Combobox1.SelectedValue.ToString should return "CND" from the items value member property.
 
To answer your question yes there is a need to query the database.
Because when the user finishes filling in the the customer info. I have the app. to return
an order# with the country extion, eg. CND00567.

Thank you in the future I'll know I can use the Select Value.ToString
 
Back
Top