在做一个项目,ASP.NET操作MYSQL数据库的,使用参数化方法,开始的时候用@,发现不成,后来上网查了才知道,原来得用?,代码如下:用到了我自己写的那个MYSQLHELPER类
MySqlConnection conn = new MySqlConnection(connstr);
conn.Open();
MySqlCommand cmd = new MySqlCommand("select count(1) from qyexam_notice where title=?title",conn);
cmd.Parameters.Add(new MySqlParameter("?title", "《测试试卷》2011/12/14 10:47:00开始"));
object obj = cmd.ExecuteScalar();
conn.Close();
conn.Open();
MySqlCommand cmd = new MySqlCommand("select count(1) from qyexam_notice where title=?title",conn);
cmd.Parameters.Add(new MySqlParameter("?title", "《测试试卷》2011/12/14 10:47:00开始"));
object obj = cmd.ExecuteScalar();
conn.Close();
Response.Write("结果:"+obj);