1

I have a probleme with a sql query :

I would like do something like :

SELECT * FROM myTable WHERE [myBoolField] IS NULL

if i run this query, i have my results,

but i would like use parameters, so i add :

SELECT * FROM myTable WHERE [myBitField] IS @myBitField

with

New SqlParameter("@myBitField", dbnull.value)

i have an error at the @myBoolField

if i pass a value like true or false, that's work ( with " = @myBitField")

Can someone help me ?

Thanks

1 Answer 1

1

You can only test for NULL using IS NULL. You cannot use parameters and there wouldn't really be any point.

DBNull.Value can be used when inserting or comparing values in code, but not on WHERE conditions since NULL is not equal to even another NULL.

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

2 Comments

oh... okay, but dbnull.value is NULL, so it's strange, no ? And as you said you can use it for insert for example
@Testman when using parameters the query is usually parsed beforehand and the parameters are not just substituted into the string. The parser will see IS @parameter and say "nope, that's not acceptable" and that's it.

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.