2013-04-18 23 views
0

我正在使用vb在asp.net上創建一個web服務。該web服務將從SQL Server 2008數據庫獲取地址並返回到Android平臺。到目前爲止,我所擁有的是獲取數據庫連接並打開它的代碼。我怎樣才能得到這個返回數據庫中所有地址的列表?我能做些什麼來讓webservice返回指定數據庫中的所有條目?我需要從一個asp.net web服務返回一個地址列表到一個Android應用程序

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 
+0

這是如何不同從[上一個問題](http://stackoverflow.com/questions/16048355/needing-to-get-a-list-of-strings-into-a-webservice?noredirect=1#comment22942651_16048355)? – rclement

回答

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

你能展示整個函數嗎? – yams

相關問題