c# sql cmd.Parameters.AddWithValue(); for is not null

If I want to add a parameter to a sql cmd object where the value is null I do this

 cmd.Parameters.AddWithValue(str, DBNull.Value);

what I need to know is how do I add a parameter value is  "is not null"
BastyonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
cmd.Parameters.AddWithValue(str, variableName);

Where variableName is the variable that holds the value to be placed in SQL Server
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
i believe you can do

cmd.Parameters.AddWithValue(str, 0);
0
jonnidipCommented:
Just a suggestion. I prefer to specify all the parameters in this way:
cmd.Parameters.Add(new SqlParameter("firstParam", SqlDbType.Int) { Value = 0 });
cmd.Parameters.Add(new SqlParameter("secondParam", SqlDbType.VarChar, 10) { Value = "test" });
cmd.Parameters.Add(new SqlParameter("thirdParam", SqlDbType.DateTime) { Value = DateTime.Now });

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

BastyonAuthor Commented:
Im not sure my point was made clearly..  I know how to add parameters with values and i know how to add a parameter is the value is null..

But in sql there is a Is Not Null   value you can set as a sql select value in the where clause..if you are adding the parameter to your query in c# how do you set a parameters value to be "Is Not Null"
0
BastyonAuthor Commented:
Question answered in other thread
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BastyonAuthor Commented:
Because no one answered it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.