Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The below code should give you what you are looking for. I am not sure if WebMethods can return custom objects like the Address object below. If it can not do that then you could convert the return type to String() and turn each Address object into a json object.</p> <p>If I was doing this from scratch, I would just return a single JSON array that contained a list of Address objects.</p> <p>Also, I have included in this method signature a skip and take parameter, as you mentioned in your comment, the web service sql query is unbounded so it could return hundreds of addresses. By using the skip and take you can limit how many are returned at once and can page through them from the client. To reduce the size of the sql query you could pass the skip and take parameters into the sql query to reduce the number of rows returned, which would improve performance as the number of addresses grows.</p> <p>There are additional safety checks you can include in the below code to prevent errors but this can get you moving.</p> <pre><code>&lt;WebMethod&gt; _ Public Function GetAddresses(skip As Integer, take As Integer) As Address() Dim resultList = New List(Of Address)() Using sqlCon As New SqlConnection() 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") sqlCon.Open() Using reader = command.ExecuteReader() While reader.Read() Dim addr = New Address() addr.Physical_Address_Street = reader.GetString(0) addr.Physical_Address_Local = reader.GetString(1) addr.Physical_Address_State = reader.GetString(2) addr.Physical_Address_Zip = reader.GetString(3) addr.Phone_Number = reader.GetString(4) resultList.Add(addr) End While End Using End Using Return resultList.Skip(skip).Take(take).ToArray() End Function </code></pre> <p>Below is a temp class object that is used above.</p> <pre><code>public class Address { public string Physical_Address_Street { get; set; } public string Physical_Address_Local { get; set; } public string Physical_Address_State { get; set; } public string Physical_Address_Zip { get; set; } public string Phone_Number { get; set; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload