登陆验证代码
SqlConnection conn = new SqlConnection("Server=(local)\\SQLExpress; User ID=sa; Password=1234;database=master;");
SqlCommand myCom = conn.CreateCommand();
myCom.CommandType = CommandType.Text;
if (txtUser.Text.Length == 0)
{
this.label4.Text=("用户名不能为空");
return;
}
myCom.CommandText = "SELECT COUNT(*) FROM loginform WHERE username='" + txtUser.Text + "'";
conn.Open();
if ((int)myCom.ExecuteScalar() == 0)
{
this.label4.Text = ("不存在此用户,请检查后重新输入!");
return;
}
myCom.CommandText = "SELECT username,password FROM loginform WHERE username='" + txtUser.Text + "'";
SqlDataReader myReader = myCom.ExecuteReader();
if (myReader.Read())
{
if (txtPass.Text == myReader[1].ToString() && txtUser.Text.Length != 0)
{
MessageBox.Show("登录成功", "恭喜");
this.Hide();
new MainForm().Show();
}
else
{
MessageBox.Show("用户" + txtUser.Text + "的密码不正确或未绑定机器码", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtPass.Focus();
return;
}
SqlCommand myCom = conn.CreateCommand();
myCom.CommandType = CommandType.Text;
if (txtUser.Text.Length == 0)
{
this.label4.Text=("用户名不能为空");
return;
}
myCom.CommandText = "SELECT COUNT(*) FROM loginform WHERE username='" + txtUser.Text + "'";
conn.Open();
if ((int)myCom.ExecuteScalar() == 0)
{
this.label4.Text = ("不存在此用户,请检查后重新输入!");
return;
}
myCom.CommandText = "SELECT username,password FROM loginform WHERE username='" + txtUser.Text + "'";
SqlDataReader myReader = myCom.ExecuteReader();
if (myReader.Read())
{
if (txtPass.Text == myReader[1].ToString() && txtUser.Text.Length != 0)
{
MessageBox.Show("登录成功", "恭喜");
this.Hide();
new MainForm().Show();
}
else
{
MessageBox.Show("用户" + txtUser.Text + "的密码不正确或未绑定机器码", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtPass.Focus();
return;
}