954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Code Not Working

Hi, I'm trying to create cascading comboboxes, and my code isn't working. I've looked at other threads and I don't know why it isn't working properly. The first combo box displays System Names and the second combobox should populate the all Locations of that specific system chosen. When I run my application, the first combobox populates without any duplicates just as it shoud but when I select a System Name from it, the location combo box populates just one entry and doesn't allow a drop down of all the other location names. Here's my code:

'---Form_Load
        Dim con As MySqlConnection = New MySqlConnection("Server=fafsv-mysql;user id=root;Password=0263;Database=gsais")
        Dim cmd As MySqlCommand = New MySqlCommand("SELECT DISTINCT SystemName FROM blsys_systems", con)
        con.Open()
        Dim myDA As MySqlDataAdapter = New MySqlDataAdapter(cmd)
        Dim myDataSet As DataSet = New DataSet()
        myDA.Fill(myDataSet, "blsys_systems")

        SystemComboBox.DataSource = myDataSet.Tables("blsys_systems")
        SystemComboBox.ValueMember = "SystemName"
        SystemComboBox.DisplayMember = "SystemName"
        Me.SystemComboBox.SelectedValue = 0
        con.Close()
        con = Nothing


That part of the code seems to be ok.. here's for the second combo box:

Private Sub SystemComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SystemComboBox.SelectedIndexChanged
        'Populates Location Name Combo box cascading from System Name
        Dim con As MySqlConnection = New MySqlConnection("Server=fafsv-mysql;user id=root;Password=0263;Database=gsais")
        Dim cmd As MySqlCommand = New MySqlCommand("SELECT LocationName, SystemName FROM blsys_systems WHERE SystemName='" & SystemComboBox.Text.ToString & "'", con)
        con.Open()
        Dim myDA As MySqlDataAdapter = New MySqlDataAdapter(cmd)
        Dim ds As DataSet = New DataSet()
        myDA.Fill(ds, "blsys_systems")

        LocationComboBox.DataSource = ds.Tables("blsys_systems")
        LocationComboBox.ValueMember = "LocationName"
        LocationComboBox.DisplayMember = "LocationName"
        LocationComboBox.SelectedValue = 0
        con.Close()
        con = Nothing
    End Sub


Once I get that to start working, the selection of the second combobox should populate textboxes and different datagrids... :(

JustineAubrey
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

Firstly, to remove the obvious, if you were to run that query directly against the database how many results should you get?

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 167
 

I should get 13 different results. However, I was able to get this to work. I just had some properties that were set that was conflicting with my code so I turned those properties off. Thanks

JustineAubrey
Newbie Poster
7 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: