如何在组合框中为每个省获得1个值 [英] How do I get 1 value for each province in combobox
问题描述
当我选择区域时,它显示以下区域,当我去省时,它显示了很多省,例如.cebu它显示所有宿务在组合框中
我想要的只有1宿务将在组合框中看到而不是许多宿务。与城市同桌
我尝试过:
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
推荐答案
您是否检查过sql字符串是否使用了正确的值?
Did you check if the sql string uses the correct values?
sql = "select * from Address where City = '" & cboCity.Text & "'"
我实际上并不是100%确定,但是在服务器控件完成之前,我执行了SelectedIndexChange-Event。
因此,请检查程序中cboCity.Text是否为空。
如果是emtyp,请尝试使用以下内容:
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") & "'"
(将cboCity替换为控件的正确名称 - >请参阅在运行时断点的immidiate窗口中的Request.Form.AllKeys())
(Replace "cboCity" with the correct name of the control -> see Request.Form.AllKeys() in the immidiate window at runtime break)
这篇关于如何在组合框中为每个省获得1个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!