C# SQL question

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
M

Maziar Aflatoun

Hi,

I have the following code
string readSQL = @"SELECT * FROM Products WHERE ProductID LIKE
@queryVal";
SqlCommand cmdProducts = new SqlCommand(readSQL, conn);

adapter.SelectCommand = cmdProducts;
adapter.SelectCommand.Parameters.Add("@queryVal", queryVal);

Which works fine. How do I add the %% to the like statement?
SELECT * FROM Products WHERE ProductID LIKE '%@queryVal%' doesn't work?
anyone knows?

Thanks
Maz.
 
How about:
adapter.SelectCommand.Parameters("@queryVal").Value = "%sample%"


Then call your commands execute command.

Bob
 
Maziar said:
Which works fine. How do I add the %% to the like statement?

Add them to the value you are assigning to the "@queryVal" variable, perhaps
like so:

cmdProducts.Parameters["@queryVal"].Value = string.Format("%{0}%", myValue);
 
Back
Top