private void AddUserForm_Load(object sender, EventArgs e) { CheckIfTeacher(); // TODO: This line of code loads data into the 'pWDBDataSet.PWDB' table. You can move, or remove it, as needed. //this.pWDBTableAdapter.Fill(this.pWDBDataSet.GetAllData); string TeacherdropSelectCommand = "select TeacherLastName from PWDB group by TeacherLastName"; MLH.FillDropDownList(TeacherdropSelectCommand, ComboTeacherLN, sqlcon); // Group Teacher name }
private void metroButton1_Click(object sender, EventArgs e) { string Loginquery = ("Select TeacherLastName, Admin from PWDB where Email='" + txtUserName.Text.Trim() + "' and Password='******'"); SqlConnection _sqlCon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|dbFile\PWDB.mdf;Integrated Security=True;Connect Timeout=30"); DataTable dt = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(Loginquery, _sqlCon); if (string.IsNullOrWhiteSpace(txtUserName.Text) || string.IsNullOrWhiteSpace(txtPassword.Text) || txtUserName.Text == "Please Enter User Name" || txtPassword.Text == "Please Enter Password") { MessageBox.Show("Please Enter user Name and Password"); } else { try { if (_sqlCon.State == ConnectionState.Closed) { _sqlCon.Open(); sda.Fill(dt); if (dt.Rows.Count == 1) { MessageBox.Show(" Welcome " + dt.Rows[0][0].ToString(), "Murphy Login Helper"); this.Hide(); MLH frm = new MLH(); if (dt.Rows[0][1].ToString() == "True") { frm.ShowDialog(); } else { frm.hideTab(true); frm.ShowDialog(); } this.Close(); } else { MessageBox.Show("Please check your credentials and try again!", "Failed to Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtPassword.Clear(); txtPassword.Focus(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Message"); } finally { _sqlCon.Close(); } } }