我正在創建一個窗體,其中用戶必須提供州名和城市名稱。城市依賴於國家。從其他組合框的選定項目填充組合框
代碼用於填充城市:
Dim ds As DataSet = New DataSet
Dim adapter As New OleDb.OleDbDataAdapter
Dim sql As String
sql = "SELECT * from statestab order by `state` ASC;"
adapter.SelectCommand = New OleDb.OleDbCommand(sql, con)
adapter.Fill(ds)
ComboBoxstate.DataSource = ds.Tables(0)
ComboBoxstate.ValueMember = "stateid"
ComboBoxstate.DisplayMember = "state"
代碼爲城市:
Dim ds As DataSet = New DataSet
Dim adapter As New OleDb.OleDbDataAdapter
Dim sql As String
Dim st As Integer
st = ComboBoxstate.SelectedValue.ToString()
sql = "SELECT * from citytab where stateid=st order by `cityname` ASC;"
adapter.SelectCommand = New OleDb.OleDbCommand(sql, con)
adapter.Fill(ds)
citycombo.DataSource = ds.Tables(0)
citycombo.ValueMember = "cityid"
citycombo.DisplayMember = "cityname"
在下拉列表中,當選擇城市化,我撥打市加載功能來填充城市組合框。 但我無法填充城市組合框。
什麼不工作?你得到一個錯誤或國家不顯示? – phil652 2015-03-25 12:18:20
它看起來像你沒有將狀態ID傳入你的第二個查詢中,而只是文本「st」而不是「st」變量的值。除非你在表中有一個名爲'st'的列,否則我希望你看到一個SQL異常? – 2015-03-25 12:39:41
我有一個列名稱stateid城市選項卡,這也是目前statestab – 2015-03-25 16:53:02