Populate ComboBox from SQL Table, based on other ComboBox
Posted on 2013-05-31
I have seen this question all over the general Internet, and on E.E, but have not seen a viable answer. I am using Visual Studio 2010, building a Windows Form project with Visual Basic. I have a ComboBox, where the user selects the Site (cboSite). I want the cboLines ComboBox to contain only those Lines associated with the Site chosen (from the Lines table). The form loads with all ComboBoxes populated, and the user has the chance to change the default entries. The default Site comes from a Global Public variable, chosen at time of login.
I've seen some suggested code involving GetConnectionString, SQLConnection(ConnectionString), SQLDataAdapter, etc. Everything I have tried in my project get's rejected.
I assume I will put some code in the Form Load event, to populate with the default, then put the same code in the SelectedIndexChanged event, in case the user selects a new Site.
I set strSite = cboSite.selectedvalue, and I setup a SQL string like this;
strSQL = "Select Line from Lines Where Site = '" & strSite & "'"
Other than that, I'm pretty lost.