hello guys,

I have a problem with my code first is i have two combobox named facname.text(facility name) and facno.text(facility no.) and when I choose in facility name(facname.text), in the facility no.(facno.text) should display the number of facility in that particular facility name..For Example you 2 facility for bowling and 1 facility for billiard then
when you choose bowling in facility name it should display in the facno.text(facility no.)
1
2
and when you click the billiard it should be display in facno.text
1
and so on but the problem of my code it output in the facno.text(a combobox) like this
1
2
1
and if i choose again like bowling it will display in the facno.text like this
1
2
1
1
2

so far this is my code:

Private Sub facname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles facname.SelectedIndexChanged
        Dim conn7 As MySqlConnection
        'connect to DB
        conn7 = New MySqlConnection()
        conn7.ConnectionString = "server=localhost; user id=root; password=root; database=srrms"
        'see if connection failed.
        Try
            conn7.Open()
        Catch myerror As MySqlException
            MessageBox.Show("Error Connecting to Database: " & myerror.Message)
        End Try

        Dim myAdapter7 As New MySqlDataAdapter

        Dim sqlquery7 = "SELECT * FROM facilitydata"
        Dim myCommand7 As New MySqlCommand()
        myCommand7.Connection = conn7
        myCommand7.CommandText = sqlquery7
        'start query
        myAdapter7.SelectCommand = myCommand7
        Dim myData7 As MySqlDataReader
        myData7 = myCommand7.ExecuteReader()
        Try
            While myData7.Read

                Try

                    facno.Text = "No."


                    If facname.Text = (myData7!facname) = True Then
                        facno.Items.Add(myData7.Item("facno"))
                        

                    End If
                  


                Catch ex As Exception
                    MsgBox("!ERROR!") '/to check for error
                End Try

            End While
        Catch ex As Common.DbException
            MsgBox(ex.ToString)
        End Try

    End Sub

simple answer

private sub facname_click()
facno.items.clear()
end sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.