What is wrong with this code? It produces 7 errors, but I copied it almost word for word from an online article.
Here is the procedure code that I am calling.
Code:
Imports System.Xml
Imports System.Xml.XmlReader
Dim SQLXMLReader As XmlReader
SqlCommand.CommandText = "GetZipcodesForDistance"
SqlCommand.CommandType = CommandType.StoredProcedure
SqlCommand.Connection = SqlConnection
SqlCommand.Parameters.Add(New SqlClient.SqlParameter("Zipcodes in range", SqlDbType.VarChar, 100, ParameterDirection.Output, False, 30, 0, "%", DataRowVersion.Current, "%"))
SqlDataReader = SqlCommand.ExecuteReader()
SQLXMLReader = SqlCommand.ExecuteXmlReader()
While (SQLXMLReader.Read)
Page.Response.Write(SQLXMLReader.ReadOuterXml())
End While
Here is the procedure code that I am calling.
Code:
ALTER Procedure GetZipcodesForDistance(
@OriginalZipCode nVarChar(7),
@Distance Float)
AS
SET NOCOUNT ON
-- Declare some variables that we will need.
Declare @Longitude Float,
@Latitude Float,
@MinLongitude Float,
@MaxLongitude Float,
@MinLatitude Float,
@MaxLatitude Float
-- Get the lat/long for the given zip
Select @Longitude = Longitude_West,
@Latitude = Latitude_North
From zipcode
Where ZipcodeID = @OriginalZipCode
-- Calculate the Max Lat/Long
Select @MaxLongitude = dbo.LongitudePlusDistance(@Longitude, @Latitude, @Distance),
@MaxLatitude = dbo.LatitudePlusDistance(@Latitude, @Distance)
-- Calculate the min lat/long
Select @MinLatitude = 2 * @Latitude - @MaxLatitude,
@MinLongitude = 2 * @Longitude - @MaxLongitude
-- The query to return all zips within a certain distance
Select ZipcodeID
From zipcode
Where Longitude_West Between @MinLongitude And @MaxLongitude
And Latitude_North Between @MinLatitude And @MaxLatitude
And dbo.CalculateDistance(@Latitude, @Longitude, Latitude_North, Longitude_West) <= @Distance FOR XML AUTO
RETURN