Click here to Skip to main content
12,074,926 members (58,110 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
hello
.....
I have problem in my code...
In this code can't fill combobox3 when combobox2 selected changes
please help me .....

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

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 26-Apr-13 2:02am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100