I'm populating a combobox drop down list from a table (tblService) which works fine - here is the code:
Dim strSQL As String = "SELECT * FROM tblService" Dim cbda As New SqlDataAdapter(strSQL, cs) Dim cbds As New DataSet cbda.Fill(cbds, "tblService") With ComboBox1 .DataSource = cbds.Tables("tblService") .DisplayMember = "ServiceName" .ValueMember = "ServiceName" .SelectedIndex = 0 End With
When I click the save button, it runs a stored procedure which saves the selected value back to a main table (tblTop). Again here is the code:
Dim cmd As New SqlCommand("updatetblTop", cs) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("service1", SqlDbType.VarChar).Value = ComboBox1.SelectedValue cmd.ExecuteNonQuery()
When I check the table, it correctly saves the value.
However - when I run the form it defaults to the first value on the drop down list - not the item that I have saved in the database. Here is the code for when I load my form:
Does anyone have any ideas why this happens?
This post has been edited by frankwright1: 09 May 2013 - 07:17 AM