//When the login button is clicked, validate the username and password, then either: Display an error, or create the next form private void btnLogin_Click(object sender, EventArgs e) { string user = txtUsername.Text; string pass = txtPassword.Text; if (validUser(user, pass)) { Main_Form main = new Main_Form(facList, getUserIndex(user)); this.Hide(); main.Show(); } else { MessageBox.Show("Invalid username or password"); } }
private void btnLogin_Click(object sender, EventArgs e) { SqlConnection sqlcon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Amanda Bakalarczyk\source\repos\EARS\EARS\EARS_DB.mdf;Integrated Security=True;Connect Timeout=30"); String query = "SELECT * FROM Login_Table WHERE username ='******' AND password = '******'"; SqlDataAdapter adapter = new SqlDataAdapter(query, sqlcon); DataTable dtbl = new DataTable(); adapter.Fill(dtbl); if (dtbl.Rows.Count == 1) { Main_Form main = new Main_Form(); this.Hide(); main.Show(); } else { MessageBox.Show("Incorrect username or password"); } }