c# sql cmd.Parameters.AddWithValue(); for values other than '='

I am able to add values I do thing like this.

cmd.Parameters.AddWithValue(paraname, paravalue);    and by default this behavior create a sql query of '='

for example   Select * from tbl where col_a = @col_a

if @col_a is 5

to put into a parameter

cmd.Parameters.AddWithValue(@col_a, 5);

but what woud I do if I didnt want it to be '='

for example

How would I add a int parameter for >   or for <>?

How would I add a parameter for LIKE in a string ?

How would I add a parameter for 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.

käµfm³d 👽Commented:
but what woud I do if I didnt want it to be '='
Then change your query. The parameter has nothing to do with what operation your query is performing.

You should have a line like:

cmd.CommandText = "Select * from tbl where col_a = @col_a";

Open in new window


...or:

SqlCommand cmd = new SqlCommand("Select * from tbl where col_a = @col_a", connection_instance);

Open in new window


You need to adjust whichever version you have.

e.g.

cmd.CommandText = "Select * from tbl where col_a > @col_a";

Open in new window


...or:

cmd.CommandText = "Select * from tbl where col_a LIKE @col_a";

Open in new window


...or:

cmd.CommandText = "Select * from tbl where col_a IS NOT NULL";

Open in new window

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
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.