Sasindu Sasindu - 3 months ago 8
SQL Question

How to open separate window for each user

I want to make a login form which open separate window for each user
type. In this program database have 3 columns.(username, password ,usertype) there are 3 user types in this program (admin, manager, user) & each user type have separate window.


  1. admin = Form2

  2. manager = Form3

  3. user = Form4



Here is my login button code. Please, help me to make this open separate
window for each user type.

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");
}

Answer

I think you have add a column in login table user type . user type column has derive admin,user,manager etc. Then you will easily verify

if(dt.rows[0]["user_type"].tostring()=="Admin")
{
// which form you show

}

if(dt.rows[0]["user_type"].tostring()=="User")
{
// which form you show

}

if(dt.rows[0]["user_type"].tostring()=="Manager")
{
// which form you show

}

i hope this code help you.if any query please comment.

Comments