I have a webservice that will return currently all address's in the database. That database has[Location]Geography column, a Lat decimal column and a Long decimal column. Along with typical address information. I am very new to database programming and I was wondering if I could modify the Query below to only return the 10 closest locations? I am using SQL Server 2008 and I have created a simple webservice as noted below. Also how do I modify the function below to pass in the current lat and long from the user of the webservice?
<
WebMethod()> _
PublicFunctionGetShelters(ByValLatAsDouble,ByValLonAsDouble,ByValtakeAsInteger)AsShelter()
DimresultList =NewList(OfShelter)()
UsingsqlConAsNewSqlConnection()
sqlCon.ConnectionString =
"Data Source=(local);Initial Catalog=DB;User ID=Turd;Password=Ferguson"
Dimsql =<sql>
SELECT
[Physical_Address_Street]
, [Physical_Address_Local]
, [Physical_Address_State]
, [Physical_Address_Zip]
, [Phone_Number]
FROM Gas_Stations
WHERE Location_Type = 2
</sql>
DimcommandAsNewSqlCommand()
command.CommandText =
CStr(sql)
command.Connection = sqlCon
sqlCon.Open()
Usingreader = command.ExecuteReader()
Whilereader.Read()
Dimshelter =NewShelter()
shelter.Physical_Address_Street = reader.GetString(0)
shelter.Physical_Address_Local = reader.GetString(1)
shelter.Physical_Address_State = reader.GetString(2)
shelter.Physical_Address_Zip = reader.GetString(3)
shelter.Phone_Number = reader.GetString(4)
resultList.Add(shelter)
EndWhile
EndUsing
EndUsing
ReturnresultList.Take(take).ToArray()
EndFunction
MB