我需要从asp.net webservice返回一个Adresses列表到Android应用程序

时间:2013-04-18 14:28:57

标签: android asp.net vb.net web-services sql-server-2008

我正在使用vb在asp.net上创建一个web服务。此Web服务将从SQL Server 2008数据库获取地址并返回到Android平台。到目前为止,我所拥有的是获取数据库连接并打开它的代码。如何让它返回数据库中所有地址的列表?如何让webservice返回指定数据库中的所有条目?

Public Class Service1 Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function GetAddresses() As FuelStop()
        Dim sqlCon As New SqlConnection
        Dim resultList = New List(Of FuelStop)()
        Try
            sqlCon.ConnectionString = "Data Source=google.watersports.com;Initial Catalog=myDb;Persist Security Info=True;Connect Timeout=30;User ID=****;Password=******"
            Dim command As New SqlCommand("SELECT @Physical_Address_Street, @Physical_Address_Local, @Physical_Address_State, @Physical_Address_Zip, @Phone_Number FROM Gas_Stations WHERE Location_Type = 1")
            command.Parameters.Add("@Physical_Address_Street", SqlDbType.VarChar, 50).Value = "Physical_Address_Street"
            command.Parameters.Add("@Physical_Address_Local", SqlDbType.VarChar, 50).Value = "Physical_Address_Local"
            command.Parameters.Add("@Physical_Address_State", SqlDbType.VarChar, 50).Value = "Physical_Address_State"
            command.Parameters.Add("@Physical_Address_Zip", SqlDbType.VarChar, 50).Value = "Physical_Address_Zip"
            command.Parameters.Add("@Phone_Number", SqlDbType.VarChar, 50).Value = "Phone_Number"
            command.Connection = sqlCon
            sqlCon.Open()

至于Fuel Stop课程,我只有

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
End Class

1 个答案:

答案 0 :(得分:1)

嗯,我认为你已经过度复杂了,试试这个:

Public Function GetAddresses() As FuelStop()
    Dim sqlCon As New SqlConnection
    Dim resultList = New List(Of FuelStop)()
    Try
        sqlCon.ConnectionString = "Data Source=google.watersports.com;Initial Catalog=myDb;Persist Security Info=True;Connect Timeout=30;User ID=****;Password=******"
        Dim command As New SqlCommand("SELECT Physical_Address_Street, Physical_Address_Local, Physical_Address_State, Physical_Address_Zip, Phone_Number FROM Gas_Stations WHERE Location_Type = 1")
        command.Connection = sqlCon
        sqlCon.Open()