Sql参数的模糊查询,'%@Brand%'这个不知道要在C#中怎么加

来源:百度知道 编辑:UC知道 时间:2024/06/18 15:32:31
string sql = "select ... from CarsInfo where brand = '%@brand%'";
这是构造带参数的字符串不行

望高手赐教,不胜感激
'%'+@brand+'%'" 这种好像不行啊,刚试了一下

string sql = "select ... from CarsInfo where brand = '%'+@brand+'%'";

SqlParameter[] parameters = {
new SqlParameter("@brand","赋值")};
或同3楼
还有模糊查询 的话用 like
select ... from CarsInfo where brand like '% @brand% '"

你也可以用存储过程

string sql = "select ... from CarsInfo where brand like '%@brand%'";

SqlParameter[] parameters ={
new SqlParameter("@brand",SqlDbType.NVarChar,100)};
parameters[0].Value = brand;

string sql = "select ... from CarsInfo where brand like '%@brand%'";

因为 '%@brand%' 是一个通配符 所以必需用 like 来修饰
这么讲希望你能明白