日期:2014-05-17  浏览次数:20778 次

用SQL2008做了一个登陆界面,注册,登陆没问题,但是登陆时密码输入次数不增加,求解!
新手,用SQL2008做了一个登陆界面,注册,登陆没问题,但是登陆时密码输入次数不增加,求解!
//登录按钮       
 private void btnLogin_Click(object sender, RoutedEventArgs e)
        {                        
                int errortimes = sqlHelper.checkErrorTimes(txtUserName.Text.Trim()); 
                if (errortimes >= 3)
                {
                    MessageBox.Show("输入次数超过三次,用户已锁定!");
                    return;
                }
                if (sqlHelper.check(txtUserName.Text.Trim(), pbPassWord.Password.Trim()))
                {
                    Comsume comWin = new Comsume();
                    comWin.Show();
                    this.Close();
                }
                else
                {
                    sqlHelper.errorTimes(++errortimes, txtUserName.Text.Trim());
//密码输错后感觉数据库中的ErrorTimes不增加!
                    MessageBox.Show("登录失败,用户名或密码不正确!");                    
                }
        }

以下为sqlHelper语句(数据库连接语句均已放到配置文件中,测试连接没问题,登陆也没问题,就是密码输错次数不更新)
        //更新用户输入密码错误次数
        public static void errorTimes(int i, string name)
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = string.Format("update T_Users set ErrorTimes={0} where UserName='{1}'", i, name);