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

c#制作的口令登陆界面 怎么实现只给三次机会
Password frmPassword = new Password();
            DialogResult dr = frmPassword.ShowDialog();
            if (dr == DialogResult.Cancel)
                Application.Exit();
            else
            {
                SqlConnection oledbConn = new SqlConnection();//连接数据库
                oledbConn.ConnectionString = @"Data Source=O8RS63RAGSIE4AR;Initial Catalog=hrone;Integrated Security=True";
                oledbConn.Open();//打开数据库连接
                SqlCommand oledbCmd = new SqlCommand();
                oledbCmd.Connection = oledbConn;
                oledbCmd.CommandText = @"SELECT 0 FROM test WHERE username = @u1;
                    SELECT 0 FROM test WHERE username = @u2 AND password = @p1; SELECT isnull(lockcnt, 0) lockcnt FROM test WHERE username = @u3 AND password = @p2 AND isnull(lockcnt, 0) < 3";
                oledbCmd.Parameters.Clear();//
                SetParam(oledbCmd, "@u1", frmPassword.TxtUserName.Text);
                SetParam(oledbCmd, "@u2", frmPassword.TxtUserName.Text);
                SetParam(oledbCmd, "@p1", frmPassword.TxtPassword.Text);
                SetParam(oledbCmd, "@u3", frmPassword.TxtUserName.Text);
                SetParam(oledbCmd, "@p2", frmPassword.TxtPassword.Text);


                SqlDataReader oledbReader = oledbCmd.ExecuteReader();//从数据库读取行
              
                
                    if (oledbReader.HasRows)//判断数据集是否为空
                    {
                        oledbReader.NextResult();
  &