I've connected a SQL database called Data to a windows form application in visual studio C#, the database contains one table called Login.
The table displays like this:
Here is image link to how data looks inside my table, so basically I will have Username, Password and Role (I have two types of roles which means user is either Admin or Client):
I have made a Login form called Login where users can enter username and password from the database which will take them to a form I've called AdminMenu. I have also made a Form called MenuForm, which I want users whose role is Client to be directed to when they login.
The problem is that I have only made the login so that all users will be directed to the AdminMenu when logging in even if their role isn't Admin. Can someone adapt my code so that users who have the role of Client will be directed to MenuForm when logging in, whereas users that have the role of Admin will be directed to AdminMenu form.
Here's is my code for Login Form:
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|Data.mdf;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("Select Role from Login Where UserName='" + textBox1.Text + "' and Password='" + textBox2.Text + "' ",con);
DataTable dt = new System.Data.DataTable();
sda.Fill(dt);
if(dt.Rows.Count == 1)
{
this.Hide();
AdminMenu ss = new AdminMenu();
ss.Show();
}
}
private void Login_Load(object sender, EventArgs e)
{
}
}
}