我正在使用 Visual Studio 2010 和 vb.net 创建一个 .asmx 网络服务,并使用 SQL Server 2008,但下面的查询提供了数据库中的所有地址。我需要将下面的查询修改为返回十个最近位置的空间查询。Lat 和 Long 是小数,但数据库中有一个名为 [Location] 的地理列。帮助!
<WebMethod()> _
Public Function GetFuelStops(ByVal Lat as Double, ByVal Long as Double) As FuelStop()
Dim resultList = New List(Of FuelStop)()
Using sqlCon As New SqlConnection()
sqlCon.ConnectionString = "Data Source=(local);Initial Catalog=Example_DB;User ID=Turd;Password=Fergison"
Dim sql = <sql>
SELECT
[Physical_Address_Street]
, [Physical_Address_Local]
, [Physical_Address_State]
, [Physical_Address_Zip]
, [Lat]
, [Long]
, [Phone_Number]
FROM Gas_Stations
WHERE Location_Type = 1
</sql>
Dim command As New SqlCommand()
command.CommandText = CStr(sql)
command.Connection = sqlCon
sqlCon.Open()
Using reader = command.ExecuteReader()
While reader.Read()
Dim fuelStop = New FuelStop()
fuelStop.Physical_Address_Street = reader.GetString(0)
fuelStop.Physical_Address_Local = reader.GetString(1)
fuelStop.Physical_Address_State = reader.GetString(2)
fuelStop.Physical_Address_Zip = reader.GetString(3)
fuelStop.Phone_Number = reader.GetString(4)
resultList.Add(fuelStop)
End While
End Using
End Using
Return resultList.Skip(skip).Take(take).ToArray()
End Function