首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

用SQL2008做了一个登陆界面,注册,登陆没有关问题,但是登陆时密码输入次数不增加,求解

2013-11-08 
用SQL2008做了一个登陆界面,注册,登陆没问题,但是登陆时密码输入次数不增加,求解!新手,用SQL2008做了一个

用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);
                conn.Open();
                conn.Close();
            }
        }


        //检测用户是否输入错误超过三次
        public static int checkErrorTimes(string name)
        {          
            using (SqlCommand cmd = new SqlCommand())
            {
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.SelectCommand.Connection = conn;
                conn.Open();                              
                cmd.CommandText=string.Format("select * from T_Users where UserName='{0}'", name);                            
                DataSet ds = new DataSet();
                adapter.Fill(ds);
                DataTable tb1 =ds.Tables[0];


                DataRow row = tb1.Rows[0];
                conn.Close();
                int result=Convert.ToInt32(row["ErrorTimes"]);
                return result;
            }
        } SQL net c# 登陆 密码
[解决办法]
int errortimes 声明为全局的

热点排行