Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2014
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