0

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

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()

至于加油站课程,我所拥有的只是

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
4

1 回答 1

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()
于 2013-04-18T16:23:39.883 回答