Fill ComboBox from SQL (show one field, select another)
Posted on 2013-05-29
I have my SQL server DataSources all setup. I drag a ComboBox over to my Windows Form. I'd think I could just work with the properties under Databindings, like Datasource, and choose what table I want, what field I want to show in the ComboBox, and what field I want saved to the variable, once chosen. There are properties there like "DisplayMember" and "ValueMember", but I can't get anything to work out. This is extremely easy to do in Access. Why is it so hard in Visual Studio 2010?? Is it any easier in VS 2012?
Do I have to write a whole SQL query manually in code? Do I have to run a loop to the end of the file to assign the values? Do I run this code in the Form Load Class? I saw something about Sub Fill_combobox1(Category as String); Can this subroutine be used to fill the box?
My ComboBox is named cboSites, the table is Sites in the Production_DataSet source, I want all of the entries in the [Site Description] field to show in the ComboBox, and once a user chooses one of the Sites, I want to use the [Site] field for a query later in the form.
How do I make this happen?