I’m new to Visual Studio 2010. I’m creating a login form and in the login form there is a combobox and a textbox. The items in combobox is the list of positions of the employees. Whenever a user click the login button there should be an if statement in the login button so that there are forms will open in a specific position of the employees. Please help.
This is the screenshot:

This is the code:
private void loginbutton_Click(object sender, EventArgs e)
{
string MyConString = "SERVER=localhost;" + "DATABASE=timekeeping;" + "UID=root;" + "PASSWORD=admin;";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select username, password from users";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
if (username_login.Text == Reader[0].ToString() && password_login.Text == Reader[1].ToString().Trim())
{
username = Reader[0].ToString();
password = Reader[1].ToString();
}
}
if (username_login.Text == username && password_login.Text == password.Trim())
{
this.Hide();
Home form = new Home();
//form.userSession(lname, fname);
form.Show();
}
else MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
connection.Close();
}
I haven’t included yet the combobox because I don’t know what to put in here.
I think you need to reconsider your design:
It would be better if you stored the roles (position) of the users in the/a database.
If someone correctly identifies himself load the role(s) for that user and then open the correct form/application. Do not let the user select his role.
Have a look at the Membership and Role providers they’re not just for ASP.NET, you can use them in Winforms as well:
Excellent set of tutorials: