Click here to Skip to main content
15,904,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i select region it shows the following region and when i go to province it shows a lot of province repeatedly like for example.cebu it shows all cebu in combobox
all i want is only 1 cebu will see in combobox instead of many cebu. thesame with city

What I have tried:

Private Sub cboRegion_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboRegion.SelectedIndexChanged
        Dim oledr As OleDb.OleDbDataReader
        Connection = "select * from Address where Region = '" & cboRegion.Text & "'"
        cboProvince.Items.Clear()
        Dim acscmd As New OleDb.OleDbCommand
        acscmd.CommandText = Connection
        acscmd.Connection = OleCn
        oledr = acscmd.ExecuteReader()

        While (oledr.Read())
            cboProvince.Items.Add(oledr("Province"))
        End While
        cboProvince.SelectedIndex = -1
        acscmd.Dispose()
        oledr.Close()
    End Sub


Private Sub cboProvince_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboProvince.SelectedIndexChanged
        Dim oledr As OleDb.OleDbDataReader
        Connection = "select * from Address where Province = '" & cboProvince.Text & "'"
        cboCity.Items.Clear()
        Dim acscmd As New OleDb.OleDbCommand
        acscmd.CommandText = Connection
        acscmd.Connection = OleCn
        oledr = acscmd.ExecuteReader()

        While (oledr.Read())

            cboCity.Items.Add(oledr("City"))

        End While
        cboCity.SelectedIndex = -1

        acscmd.Dispose()
        oledr.Close()
    End Sub

Private Sub cboCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCity.SelectedIndexChanged
       Dim oledr As OleDb.OleDbDataReader
       Connection = "select * from Address where City = '" & cboCity.Text & "'"
       cboBrgy.Items.Clear()
       Dim acscmd As New OleDb.OleDbCommand
       acscmd.CommandText = Connection
       acscmd.Connection = OleCn
       oledr = acscmd.ExecuteReader()
       While (oledr.Read())
           cboBrgy.Items.Add(oledr("Barangay"))
       End While
       cboBrgy.SelectedIndex = -1
       acscmd.Dispose()
       oledr.Close()

   End Sub
Posted
Updated 7-Aug-18 23:41pm

1 solution

Did you check if the sql string uses the correct values?

sql = "select * from Address where City = '" & cboCity.Text & "'"

I'm not 100% sure actually, but I thnk the SelectedIndexChange-Event is executed BEFORE the server controls are finished.

So check if cboCity.Text is empty in the procedure.
If it's emtyp try to use the follwing:

sql = "select * from Address where City = '" &  Request.Form("cboCity") & "'"



(Replace "cboCity" with the correct name of the control -> see Request.Form.AllKeys() in the immidiate window at runtime break)
 
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