[.NET] 配合SQL寫郵遞區號查詢

看板Visual_Basic作者 (真。假凱文)時間15年前 (2011/01/03 15:50), 編輯推噓2(201)
留言3則, 2人參與, 最新討論串1/2 (看更多)
縣市 鄉鎮市區 郵遞區號 ┌──┬─┐ ┌──┬─┐ ┌────┐ │ │▼│ │ │▼│ │ │ └──┴─┘ └──┴─┘ └────┘ Country City Code (combobox) (combobox) (Label) 我將縣市做在一個SQL的資料表內 001 基隆市 002 台北市 003 新北市 . . . 另一個資料表則是記錄鄉鎮市區的郵遞區號 . . 002 中和區 236 002 板橋區 232 . . . 後來VB.net寫了半天 選完縣市後 會自動對應該縣市的鄉政市區 這一切都很正常 但是郵遞區號一直寫不出來,所以才上來求救了 orz Imports MySql.Data Imports MySql.Data.MySqlClient Public Class Code Dim MyVoice As New SpeechLib.SpVoice Dim Search As String = "SELECT * FROM `country`" Dim cmd As New MySqlCommand(Search, cn) Dim da As New MySqlDataAdapter Dim ds As New DataSet Dim dvCountry As New DataView Dim dvCity As New DataView Private Sub Index_Load da.SelectCommand = cmd da.Fill(ds, "Countrylist") Country.DataSource = ds.Tables("Countrylist") Country.DisplayMember = "Country" Country.SelectedIndex = -1 AddHandler Country.SelectedIndexChanged, AddressOf Country_SelectedIndexChanged Code.Text = "" End Sub Private Sub Country_SelectedIndexChanged cmd.CommandText = "SELECT `A1`.`Country`,`A2`.`City`,`A2`.`code` FROM `Country` `A1` , `Code` `A2` WHERE `A1`.`CNo` = `A2`.`CNo` And `A1`.`Country` Like '%" & Country.Text & "%'" da.Fill(ds, "City_detail") dvCountry.Table = ds.Tables("City_detail") dvCountry.RowFilter = "Country='" & Country.Text & "'" City.DataSource = dvCountry City.DisplayMember = "City" City.SelectedIndex = -1 Label49.Text = "" AddHandler City.SelectedIndexChanged, AddressOf City_SelectedIndexChanged End Sub Private Sub City_SelectedIndexChanged cmd.CommandText = "SELECT `A2`.`Code` , `A2`.`city`FROM `Country` `A1` , `Code` `A2` WHERE `A1`.`CNo` = `A2`.`CNo` And `A1`.`Country` Like '%" & Country.Text & "%' And `A2`.`City` Like '%" & City.Text & "%'" da.Fill(ds, "Code") dvCity.Table = ds.Tables("Code") Label49.Text = ????????????????? End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.124.77.75 ※ 編輯: jakevin 來自: 140.124.77.75 (01/03 16:20)

01/03 20:46, , 1F
SQL指令是對的嗎??對的話直接指定到DS中的item就好啦
01/03 20:46, 1F

01/03 20:49, , 2F
只是我覺得~用DataReader就好了吧
01/03 20:49, 2F

01/03 21:09, , 3F
@@" SQL指令都對 我在SQL側過是可以跑得
01/03 21:09, 3F
文章代碼(AID): #1D8N_BDB (Visual_Basic)
文章代碼(AID): #1D8N_BDB (Visual_Basic)