我有一張郵政編碼表以及他們的經度和緯度。 用戶帖子郵政編碼列表成多文本框和列表,創建並送入sql = "SELECT postcode, latitude,longitude FROM geocodes WHERE postcode IN (" & PCList & ")"
MySQL WHERE IN只返回最後一行
PCList格式爲
'AL7 2BQ ','B12 9BS ','B14 7QU ','B21 9SF ','B24 9PJ ','B27 7RR '
,'B33 0NG ','B42 1NN ','B63 4RH ','B64 5AB ','B65 0LG ','B70 9QL '
,'B73 5AB ','B79 7AG ','BH1 1EN ','BH1 4SX ','BH9 2HE ','BL1 8TH '
,'BL3 6JR ','BL4 9HF ','BL5 3YY ','BL8 2EQ ','BN2 5TB ','BN9 0AD' etc.
我只得到了最後的郵政編碼。我已經試過MysqlDatareader,Datasets,mySQL字符串返回工作臺中的完整列表。
如果我將sql替換爲「SELECT postcode, latitude,longitude FROM geocodes WHERE postcode LIKE 'B65%'
」,那麼我會在數據讀取器或數據集中獲得從B65開始的郵編的完整列表,但無法使其與mySQL的WHERE IN配合使用。
下面是代碼: -
Protected Sub ShowLocsButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowLocsButton.Click
Dim PCList As String = Replace(Me.PostcodeListTextBox.Text, vbCrLf, "','")
PCList = "'" & PCList & "'"
GetMarkers(PCList)
End Sub
Protected Sub GetMarkers(ByVal PCList As String)
Dim PointsDs As New DataSet
Dim PointsDa As MySqlDataAdapter
Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnString").ConnectionString
Dim conn As New MySqlConnection(ConnString)
command.Connection = conn
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
sql = "SELECT postcode, latitude,longitude FROM geocodes WHERE postcode IN (" & PCList & ")"
command.CommandText = sql
PointsDR = command.ExecuteReader()
'Dim myrow As Integer = 0
Me.VRPMap.Layers.Clear()
'MsgBox(PointsDs.Tables(0).Rows.Count)
While PointsDR.Read
Dim myPostcode As String = PointsDR.GetString(0)
Dim myLatitude As String = PointsDR.GetValue(1)
Dim myLongitude As String = PointsDR.GetValue(2)
End While
conn.Close()
末次
此問題是由我們無法看到的代碼引起的。 – Strawberry
什麼是'&PCList&' –
每個郵政編碼的最後一個空格是否縮進? – apomene