我想创建表单登录: - textboxUserName - textboxPassword - buttonLogin
我的数据库有分散用户表
如果用户名是admin,则打开表单1 如果用户名是用户打开表单2
请帮助我,谢谢
这是我的代码,没有分散用户:
try
{
if (txtUserName.Text == "" || txtPassword.Text == "")
{
MessageBox.Show("Entry Username and Password", "Error");
txtUserName.Focus();
return;
}
else
{
SqlConnection conn = new SqlConnection(@"Data Source=; Initial Catalog=; uid = sa; pwd = 123456;");
conn.Open();
SqlCommand cmd = new SqlCommand("Select Pass From Account Where UserName ='" + txtUserName.Text + "'", conn);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
if (txtPassword.Text == reader.GetValue(0).ToString())
{
MessageBox.Show("Login success!", "Success");
reader.Close();
conn.Close();
this.Hide();
//I need assistance in this paragraph
//if (user == admin) open form 1
// else open form 2
Form2 frm2 = new Form2();
frm2.ShowDialog();
}
else
{
MessageBox.Show("Wrong password", "Error");
txtPassword.Focus();
}
reader.Close();
conn.Close();
}
}
catch (Exception)
{
MessageBox.Show("Wrong Username or Password", "Error");
txtUserName.Focus();
}