DataSource failing with null integer parameter

A

Assimalyst

Hi,

I am trying to create a search page using a number of fields, mostly
strings, one is an integer. That allows the user to use any combination
of the fields to search with.

I have a datasource configured using the asp.net (v2.0) tools and the
parameters are passed from controls to a stored procedure. I have set
default values for the strings to '%' and left the default for the
integer blank. When i test the query in configuration it works fine
with a blank integer. But when i run it in the webpage the datasource
returns null if the integer field is blank. I have checked this with
the following code:

protected void gvSearchResults_DataBound(object sender, EventArgs e)
{
DataView DV =
(DataView)this.DataSourceSearchResultsGV.Select(DataSourceSelectArguments.Empty);
if (DV != null)
{
. . . .

If i remove the integer field from the query it all works fine, if i
enter an integer it works fine. So it seems to be some sort of issue
converting the blank textbox control text (that the integer is passed
from) for use in the datasource.

Any ideas how to fix this?

Here's the query:

@pkiBarcodeNumber varchar(8),
@szFirstName varchar(24),
@szSurname varchar(40),
@szDateOfBirth varchar(8),
@szPostcode varchar(8)

AS


SELECT pkiBarcodeNumber, szFirstName, szSurname, szDateOfBirth,
szPostcode
FROM tblApplicationForms
WHERE pkiBarcodeNumber = CASE WHEN @pkiBarcodeNumber IS NULL THEN
pkiBarcodeNumber ELSE @pkiBarcodeNumber END
AND szFirstName LIKE '%' + @szFirstName + '%'
AND szSurname LIKE '%' + @szSurname + '%'
AND szDateOfBirth LIKE '%' + @szDateOfBirth + '%'
AND szPostcode LIKE '%' + @szPostcode + '%'
ORDER BY pkiBarcodeNumber

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top