I have a program that uses administrator and employee login. I have two tables in SQL Server named Admin
and Employee
.
I only have one login window. I have two forms AdminForm
and EmpForm
. When username and password are entered, I want to read the two tables.
- If username and password belongs to the table
Admin
, then it will show theAdminForm
- but when username and password belong to table
Employee
, it will show theEmpForm
I'm new to SQL Server. Is there anyway Was it possible? As of now, this my code:
private void btnLogin_Click(object sender, EventArgs e)
{
using (var connect = sqlcon.getConnection())
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM administrator WHERE username = @username AND password = @password"))
{
cmd.Connection = connect;
connect.Open();
cmd.Parameters.Add("@cusername", SqlDbType.Char).Value = tbUsername.Text;
cmd.Parameters.Add("@cpassword", SqlDbType.Char).Value = tbPassword.Text;
using (SqlDataReader re = cmd.ExecuteReader())
{
if (re.Read())
{
}
else
{
}
}
}
}
}