我有一个在 Visual Studio 2010 中使用 vb.net 创建的 .asmx Web 服务。我最近修改了下面的查询并添加了“, geography::Point(@Latitude, @Longitude, 4326).STDistance(Location) * 0.00062137119”。由于我添加了我需要添加到 while reader.Read() 循环以将小数作为 web 服务的 xml 上的字符串输出 linefuelStop.Distance = reader.GetString(5) 显然不起作用我该怎么办输出到xml的距离?
网络服务代码:
<WebMethod()> _
Public Function GetFuelStops(ByVal Latitude As Double, ByVal Longitude As Double) As FuelStop()
Dim resultList = New List(Of FuelStop)()
Using sqlCon As New SqlConnection()
sqlCon.ConnectionString = "Data Source=(local);Initial Catalog=My_DB;User ID=*****;Password=*******"
Dim sql = <sql>
DECLARE @center GEOGRAPHY
SET @center = geography::Point(@Latitude, @Longitude, 4326)
SELECT TOP 10
[Physical_Address_Street]
, [Physical_Address_Local]
, [Physical_Address_State]
, [Physical_Address_Zip]
, [Phone_Number]
, geography::Point(@Latitude, @Longitude, 4326).STDistance(Location) * 0.00062137119
FROM Gas_Stations
WHERE Location_Type = 1
ORDER BY @center.STDistance(Location) ASC
</sql>
Dim command As New SqlCommand()
command.CommandText = CStr(sql)
command.Parameters.Add("@Latitude", SqlDbType.Decimal).Value = Latitude
command.Parameters.Add("@Longitude", SqlDbType.Decimal).Value = Longitude
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)
fuelStop.Distance = reader.GetString(5)
resultList.Add(fuelStop)
End While
End Using
End Using
Return resultList.ToArray()
End Function
这是我的 FuelStop.class
Public Class FuelStop
Property Physical_Address_Street As String
Property Physical_Address_Local As String
Property Physical_Address_State As String
Property Physical_Address_Zip As String
Property Phone_Number As String
Property Distance As String
End Class