做c/s项目数据库登陆模块时这样写了一段代码,输入的用户名和密码明明和数据库上面的对着,但是就是报错,
我郁闷了很久,
private void btnLogin_Click(object sender, EventArgs e)
{
if (this.checkEmpty())
{
DataBase.getConnection();
int k=DataBase.exeSqlDataReader("select ID from tb_user where User_Name='"+this.txtUser.Text.Trim().ToString()+"'and User_Pass='"+this.txtPass.Text.Trim().ToString()+"'");
if (k > 0)
{
MainForm f = new MainForm();
this.Hide();
f.Show();
DataBase.closeConnection();
}
else
{
MessageBox.Show(Form.ActiveForm,"用户名或密码错误,请重新登录!","登录失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
DataBase.closeConnection();
txtPass.Text = "";
txtUser.Text = "";
}
}
}
怎么找也找不出问题,几乎快要崩溃了,因为我看了很久都没看出来自己代码有问题,
直到
int k=DataBase.exeSqlDataReader("select ID from tb_user where User_Name='"+this.txtUser.Text.ToString().Trim()+"'and User_Pass='"+this.txtPass.Text.ToString().Trim()+"'");
把这段代码ToString()方法和Trim()调换一下位置,终于搞定了,呵呵呵!
---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ----------------------详细请查看:http://net.itheima.com/