Vb.net 如何向Web服务的xml中添加小数>;?

Vb.net 如何向Web服务的xml中添加小数>;?,vb.net,visual-studio-2010,web-services,sql-server-2008,asmx,Vb.net,Visual Studio 2010,Web Services,Sql Server 2008,Asmx,我在Visual Studio 2010中使用vb.net创建了一个.asmx Web服务。我最近修改了下面的查询,并添加了“geography::Point(@纬度,@经度,4326).STDistance(位置)*0.00062137119”。由于我添加了需要添加到while reader.Read()循环中的内容,以便在Web服务的xml上以字符串形式输出十进制数,因此行fuelStop.Distance=reader.GetString(5)显然不起作用。我该如何将距离输出到xml We

我在Visual Studio 2010中使用vb.net创建了一个.asmx Web服务。我最近修改了下面的查询,并添加了“geography::Point(@纬度,@经度,4326).STDistance(位置)*0.00062137119”。由于我添加了需要添加到while reader.Read()循环中的内容,以便在Web服务的xml上以字符串形式输出十进制数,因此行fuelStop.Distance=reader.GetString(5)显然不起作用。我该如何将距离输出到xml

Web服务代码:

<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

如果您试图将浮点数作为字符串读取,则应使用正确的类型从读取器获取浮点数:

reader.GetDecimal(5)

并将要返回的正确类型放入类中

(正如在评论中所确定的,您发现它可以起到双重作用:))


字符串以外的事物的序列化在XML中仍然是正确的(大部分情况下)。

reader.GetDecimal(5).ToString()?老实说,您应该将fuelstop.class更改为距离为十进制,它将被正确序列化。(并且不要使用.ToString())好的,所以我将FuelStop距离更改为十进制,当我使用读卡器调用时,我是否应该执行reader.getDecimal(5)?是的,因为它将以十进制形式获取值。然后应将其正确序列化为XML输出。好的,我这样做了,当我调试我的Web服务并到达fuelStop.Distance=reader.GetDecimal(5)时,Web服务返回一个无法显示的页面,它只会显示除此之外的任何内容。数据库中如何定义距离?感谢您的评论和答案。我更像是一个Java爱好者,试图学习Visual Basic和C。我很感激。
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