I have the following query in ASP.NET/C# code which is failing to return any values using a parameter...
select * from MyTable where MyTable.name LIKE @search
>
I think the issue is that you're escaping the quotes in your search
parameter, when the SQL parameter does that for you.
The percent signs should be inside the SQL Parameter value; your query just references the parameter plainly. The SQL should look like this:
select * from MyTable where MyTable.name LIKE @search
And the code should look like this:
string search = "MyValue'ToSearchForWith'Quotes";
myCmd.Parameters.AddWithValue("@search", "%" + search + "%");
Note that search
is the original value, not escaped.