如何/应该构造mysqlparameter?
这是我做的方法,但是却没有得到输出:
var cities = ce.city.SqlQuery("Select * from world.city where Name like '%@p0%'",
new MySqlParameter("@p0", kendoServerFilter.filter.Filters[0].Value))
.ToList();
var cities = ce.city.SqlQuery("Select * from world.city where Name like '%@p0%'",
new MySqlParameter("p0", kendoServerFilter.filter.Filters[0].Value))
.ToList();
var cities = ce.city.SqlQuery("Select * from world.city where Name like @p0",
new MySqlParameter("p0","'%" + kendoServerFilter.filter.Filters[0].Value + "%'"))
.ToList();
如果我通过连接字符串构建查询,则语句工作正常,但使用参数化查询时不起作用。我要去哪里错了?请帮助。
答案 0 :(得分:1)
尝试从''
登录参数值的开头和结尾删除单引号(%
)
因此您的第三个查询将是
var cities = ce.city.SqlQuery("Select * from world.city where Name LIKE @p0",
new MySqlParameter("p0","%" + kendoServerFilter.filter.Filters[0].Value + "%"))
.ToList();