【发布时间】:2016-09-03 02:28:43
【问题描述】:
我想制作一个登录表单,为每个用户打开单独的窗口 类型。在这个程序数据库中有 3 列。(用户名、密码、用户类型)在这个程序中有 3 种用户类型(管理员、经理、用户)并且每个用户类型都有单独的窗口。
- admin = Form2
- 经理 = Form3
- 用户 = Form4
这是我的登录按钮代码。请帮我把这个分开打开 每个用户类型的窗口。
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\users\sasindu\documents\visual studio 2010\Projects\Employee Database\Employee Database\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand("select * from login where username=@username and password =@password", con);
cmd.Parameters.AddWithValue("@username", textBox1.Text);
cmd.Parameters.AddWithValue("@password", textBox2.Text);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (dt.Rows.Count > 0)
{
Form3 Form = new Form3();
Form.Show();
this.Hide();
}
else
{
MessageBox.Show("Please enter Correct Username and Password");
}
【问题讨论】:
标签: c# sql .net winforms login