错误原因:
MySQLDriverCS Exception: MySQLDriverCS Error: wrong query.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '户名='admin' and 密码='123456'' at line 1
部分代码:
string str = "server=localhost;data source=users;user id=root;password=123456";
MySQLConnection DBConn=new MySQLConnection(str);
string sql = string.Format("select * from student where 用户名='{0}' and 密码='{1}'",username,password);
DBConn.Open();
MySQLCommand DBComm = new MySQLCommand(sql, DBConn); int num = (int)DBComm.ExecuteScalar(); //这就是出错地方求教各位大神!谢谢!!!
MySQLDriverCS Exception: MySQLDriverCS Error: wrong query.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '户名='admin' and 密码='123456'' at line 1
部分代码:
string str = "server=localhost;data source=users;user id=root;password=123456";
MySQLConnection DBConn=new MySQLConnection(str);
string sql = string.Format("select * from student where 用户名='{0}' and 密码='{1}'",username,password);
DBConn.Open();
MySQLCommand DBComm = new MySQLCommand(sql, DBConn); int num = (int)DBComm.ExecuteScalar(); //这就是出错地方求教各位大神!谢谢!!!
看下这个,是不是单引号需要转义啊~
看这个错误的原因
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '户名='admin' and 密码='123456'' at line 1
似乎是
select * from student where 用户名='{0}' and 密码='{1}这个SQL语句有问题,
建议楼主将这个语句在MySQL查询窗口试一下,看是否能查出结果