初学C#不知道这个登陆循环哪出错了

来源:百度知道 编辑:UC知道 时间:2024/06/19 14:45:08
if (users.Text.Trim().Length > 0 && password.Text.Trim().Length > 0)
{
base.Cursor = Cursors.WaitCursor;
//从mysql数据库读取数据进行比对
MySQLConnection DBConn;
DBConn = new MySQLConnection(new MySQLConnectionString("localhost", "mybase", "root", "tizheng", 3306).AsString);
DBConn.Open();
// MySQLCommand conn = new MySQLCommand("set names gb2312", DBConn);
// conn.ExecuteNonQuery();
MySQLCommand cmd = new MySQLCommand("select count(*) from login where Users='" + users.Text + "' and Pwd='" + password.Text + "'", DBConn);
int flag = Convert.ToInt32(cmd.ExecuteScalar()); //数据读取标记,传递用户权限
if (flag > 1)
{<

if (flag > 1)
==>
if (flag > 0)

有一条记录的话就是1,不会大于1,查不到就是0

加上Try...Catch块看看异常抛向哪里。
或者加个断点拦截一下错误。

seclect 拼写错误 select