关于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);

}

posted @ 2021-08-20 14:56  奇迹之耀  阅读(91)  评论(0编辑  收藏  举报