Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DataSource failing with null integer parameter

Thread Tools

DataSource failing with null integer parameter

Posts: n/a

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 (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(Da taSourceSelectArguments.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(,
@szFirstName varchar(24),
@szSurname varchar(40),
@szDateOfBirth varchar(,
@szPostcode varchar(


SELECT pkiBarcodeNumber, szFirstName, szSurname, szDateOfBirth,
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


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL RS Report Parameter multivalue failing Ben ASP .Net 1 06-11-2007 07:55 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? Java 5 03-29-2006 10:37 PM
DataGrid DataSource is null on postback Narshe ASP .Net 4 12-26-2005 04:37 PM
Can't get DataSource of a repeater, returns null Alan Silver ASP .Net 2 07-12-2005 01:57 PM
DBD/DBI failing to add a blank in a non-null field Perl Misc 1 12-30-2004 01:37 AM