C# SQLite Parameterized Select Using LIKE

前端 未结 2 1620
眼角桃花
眼角桃花 2020-12-16 13:08

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

2条回答
  •  伪装坚强ぢ
    2020-12-16 13:45

    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%");
    

提交回复
热议问题