关于ADO .NET sql参数化模糊查询
错误写法:
MySqlConnection conn = new MySqlConnection(connString);
string sql="select * from user where FullName like '%@fullname%' ";
using (MySqlCommand cmd = new MySqlCommand(sql, conn))
{
MySqlParameter parameter = new MySqlParameter("@fullname", FullName);
cmd.Parameters.Add(parameter);
}
正确写法
MySqlConnection conn = new MySqlConnection(connString);
string sql="select * from user where FullName like @fullname ";
using (MySqlCommand cmd = new MySqlCommand(sql, conn))
{
MySqlParameter parameter = new MySqlParameter("@fullname", "%"+FullName+ "%" );
cmd.Parameters.Add(parameter);
}