I am doing a really simple query in ASP.NET, but after I inserted the LIKE clause it stops working.
Example:
String sql = " SELECT *
FROM Products
WHERE ID = @MYID
AND Name LIKE '%@MYNAME%' ";
SqlCommand command = new SqlCommand(sql, cn);
command.Parameters.AddWithValue("@MYID", MYID.Text);
command.Parameters.AddWithValue("@MYNAME", MYNAME.Text);
If I removed the LIKE it works. Hence I am thinking its to do with the ” quotes?
The sql statement should look like this:
I am not sure I understood your comment completely, but it seems you want to use the value from a text box in your query – maybe this is what you are trying to do:
“text_box” would be the actual id of your textBox control.