I am trying to do an SQL query such as
SELECT * FROM [TABLE] WHERE hostname LIKE \'%myhostname%\';
This works fine in plain SQL, but when
You can't do that. The parameters must be complete values - it's not just a string substitution into the SQL. You could do this instead:
string sel = "SELECT * FROM [TABLE] WHERE hostname LIKE @host"; ... command.Parameters.AddWithValue("@host", "%myhostname%");