Hello. I'm new to programming and I'm using vb.net 2010 and I'm stuck with this problem. So here are the details, I have 2 tables in my database, a product table and a category table. In my product table I have product no, product description and category no. In the category table i have category no and category desciption. So this is where Ive been stuck for the entire day, I want my combox(product) to populate based on what is in the combobox(category). For example I have "Chair" in my combobox(category), then what would appear in the combobox(product) would be "sofas", "dining chair" etc.
'the part below is where the program will read the category description from my database Sub fillcomboDesc() Dim fillcatDesc As MySqlCommand = New MySqlCommand("Select catDesc from category;", connection) Dim reader1 As MySqlDataReader Try reader1 = fillcatDesc.ExecuteReader While (reader1.Read()) cmbDescrip.Items.Add(reader1.GetString(0)) End While fillcatDesc.Dispose() reader1.Close() Return Catch ex As Exception End Try End Sub 'the part below is where the program will display category description based on my choice Private Sub cmbDescrip_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbDescrip.SelectedIndexChanged Dim cmbcatDescCommand1 As MySqlCommand = New MySqlCommand("Select * from category where catDesc=@field2;", connection) Dim reader1 As MySqlDataReader Try With cmbcatDescCommand1 .Parameters.AddWithValue("@field2", cmbDescrip.Text) End With reader1 = cmbcatDescCommand1.ExecuteReader() If (reader1.Read()) Then txtcatNo.Text = (reader1("catNo")) End If cmbcatDescCommand1.Dispose() reader1.Close() Catch ex As Exception End Try End Sub 'the part below here is supposed to be where my combobox(product) and combobox(category) should connect Private Sub cmbProduct_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbProduct.SelectedIndexChanged Dim cmbProductCom1 As New MySqlCommand Dim newvalue As String Dim dataset As New DataSet Dim table As New DataTable Dim adapter As New MySqlDataAdapter connection.ConnectionString = sqlMainConnector newvalue = cmbProduct.SelectedValue cmbProductCom1.CommandText = "select productDesc from product where catno=" & newvalue & ";" adapter.selectcommand = cmbProductCom1 adapter.Fill(dataset, "product") table = dataset.Tables("product") cmbDescrip.DataSource = table cmbDescrip.DisplayMember = "productDesc" cmbDescrip.ValueMember = "catno" End Sub
Im sorry if it's all messed up. So guys could you help. Great help would really be appreciated.