1

I have one page to view all Universities,and I want this page to view filtered data as per city, I added to SQL statement:

WHERE (Cit_Id = @Unv_CitId OR @Unv_CitId IS NULL)

and set DefaultValue of @Unv_CitId parameter to NULL, but I got error,

How can I solve this issue?

2
  • 2
    What is the error ? please share full query instead of just where clause. Commented Oct 23, 2012 at 5:10
  • Show us the exception you are receiving. Commented Oct 23, 2012 at 5:11

5 Answers 5

3

You should assign value DBNull.Value rather then null.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, however I got this error "Conversion failed when converting the nvarchar value 'DB.Null' to data type int."
I think you don't need 'OR @Unv_CitId IS NULL' part of your query.
and change it to the DBNull.Value rather then DBNull.
0

you can try this

where (Cit_Id = isdbnull(@Unv_CitId)?null:@unv_citId

Comments

0

I'm not 100% sure of your intention, but what about something like this:

WHERE (Cit_Id = @Unv_CitId OR Cit_Id IS NULL)

Your original query looks a little odd with @Unv_CitId IS NULL in there: this clause isn't checking against a field, merely against the value being passed in.

Comments

0

Yes now it is ok, I set SqlDataSource's CancelSelectOnNullParameter property to False, and delete the defaultValue of the parameter

Comments

0

delclare @Unv_CitId as null while declaring parameter in procedure as shown below

@Unv_CitId int NULL

so the varibale will accept null value as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.