作者jakevin (真。假凯文)
看板Visual_Basic
标题[.NET] 配合SQL写邮递区号查询
时间Mon Jan 3 15:50:32 2011
县市 乡镇市区 邮递区号
┌──┬─┐ ┌──┬─┐ ┌────┐
│ │▼│ │ │▼│ │ │
└──┴─┘ └──┴─┘ └────┘
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)
1F:推 cawQQ:SQL指令是对的吗??对的话直接指定到DS中的item就好啦 01/03 20:46
2F:推 cawQQ:只是我觉得~用DataReader就好了吧 01/03 20:49
3F:→ jakevin:@@" SQL指令都对 我在SQL侧过是可以跑得 01/03 21:09