public void userLogin() { try { loginCommand = "select User_Name, Password, Role from User_Master where User_Name = '" + login + "'"; obj = new ConnectDb(); dr = obj.getData(loginCommand); if (dr.HasRows == true) { while (dr.Read()) { userID = dr["User_Name"].ToString(); tempPass = dr["Password"].ToString(); role = dr["Role"].ToString(); tempPass.Trim(); password.Trim(); if (password == tempPass) { if (role == "Administrator") { role_Id = 1; } else if (role == "Manager") { role_Id = 2; } else if (role == "Executive") { role_Id = 3; } MessageBox.Show("Welcome " + userID + " to Billing software of " + comboBox1.Text + "", "Login", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Hide(); Main_Screen md = new Main_Screen(txtLogin.Text, role_Id, company, connectionString); md.ShowDialog(); } else { MessageBox.Show("Invalid Password", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Invalid User name", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception e) { MessageBox.Show("The following error occured:\n" + e.Message.ToString(), "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { dr.Close(); } }