How to use sql parameters for a select query?

前端 未结 3 975
孤城傲影
孤城傲影 2021-01-21 07:59

I need to fetch the records based on a \'like\' match against a set of records,

The below query im using is not working . Does anyone knows what\'s wrong with the query?

3条回答
  •  -上瘾入骨i
    2021-01-21 08:32

    String.Format needs a placeholder, like {0} {1} etc.

    sqlCommand.CommandText = "SELECT * FROM Customer WHERE Name LIKE @Name;";
    sqlCommand.Parameters.AddWithValue("@Name", String.Format("%{0}%", searchString));
    

提交回复
热议问题