Hi there - I'm a little stuck with something and could do with some help. The situation I have is as follows.
On my webform, the user will enter a zip code and be presented with a list of centres that are within a set distance from there
This involves two tables. Table_ZipCodes contains grid references (a northing and an easting) for a whole bunch of zip codes; Table_centres contains address details of training centres.
On clicking submit I need to run a process that retrieves the northing and easting for the zip code and then passes this onto a stored procedure that performs the distance calculation and returns the details of the centres that meet with the criteria.
I have got this working as follows:
1) User enters zip code
2) A datareader object is declared which then uses a stored procedure to return the 'easting' and 'northing' for the zip code. These values are then stored as variables
Code:
cnCentreFinder.Open()
drPCodeValues = cmdPostcodeSelect1.ExecuteReader
drPCodeValues.Read()
varEasting = drPCodeValues("Easting")
varNorthing = drPCodeValues("Northing")
3) These variables are then used as parameters for the 2nd stored procedure, along with the distance value (selected from a dropdown menu):
Code:
cmdSelectCentres.Parameters("@InNorthing").Value = intNorthing
Code:
cmdSelectCentres.Parameters("@InEasting").Value = intEasting
cmdSelectCentres.Parameters("@Distance").Value = ddlDistance.SelectedItem.Value
drPCodeValues.Close()
4) Finally the results are bound to a datagrid and displayed:
Code:
daCentreResults.Fill(dsCentreResults)
Code:
dgCentreResults.DataSource = dsCentreResults
dgCentreResults.DataBind()
This all works fine. However, what I now need to add is a way of telling the user if the zip code they entered does not exist. The obvious way is to see if there are any values in the datareader that stores the Northing and Easting, but everything I read seems to suggest that you can't do a .Count operation on a datareader. Is this correct? If so, how can I get round this?