Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
.....
I have problem in my code...
In this code can't fill combobox3 when combobox2 selected changes
please help me .....

VB
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim adapter As New SqlDataAdapter()
        Dim ds As New DataSet()
        Dim con As New SqlConnection("Data Source=.;Initial Catalog=system saling;Integrated Security=True")


        Try
            If IsNumeric(ComboBox1.SelectedValue) Then

                Dim com As New SqlCommand("select id_col,collection_name from colec_items where (card_no = '" & ComboBox1.SelectedValue & "')", con)
                con.Open()
                adapter.SelectCommand = com
                adapter.Fill(ds)
                adapter.Dispose()
                com.Dispose()
                con.Close()


                ComboBox2.DataSource = ds.Tables(0)
                ComboBox2.ValueMember = "id_col"
                ComboBox2.DisplayMember = "collection_name"
            End If
        Catch ex As Exception
            'MessageBox.Show("errogggggggggggggvgr")
        End Try


    End Sub


VB
Private Sub ComboBox2_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedValueChanged
       Dim adapter As New SqlDataAdapter()
       Dim ds As New DataSet()
       Dim con As New SqlConnection("Data Source=.;Initial Catalog=system saling;Integrated Security=True")



       Try
           If IsNumeric(ComboBox2.SelectedValue) Then

               Dim com As New SqlCommand("select item_no,item_name from item_info where (collec_no = '" + ComboBox2.SelectedValue + "')", con)
               con.Open()
               adapter.SelectCommand = com
               adapter.Fill(ds)
               adapter.Dispose()
               com.Dispose()
               con.Close()


               ComboBox3.DataSource = ds.Tables(0)
               ComboBox3.ValueMember = "item_no"
               ComboBox3.DisplayMember = "item_name"

           End If
       Catch ex As Exception

       End Try

   End Sub
Posted

1 solution

The Select query :-
Dim com As New SqlCommand("select item_no,item_name from item_info where (collec_no = '" + ComboBox2.SelectedValue + "')", con)
has WHERE clause is collec_no, while ComboBox2.SelectedValue contains ComboBox2.DisplayMember = "collection_name".
Hence the query is not executing properly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900