private void AddButton_Click(object sender, EventArgs e) { String username, password, name, phone, cpassword; username = usernameField.Text; password = passwordField.Text; cpassword = password2Field.Text; name = nameField.Text; phone = phoneField.Text;// // SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"|DataDirectory|\\DemoDatabase.mdf\";Integrated Security=True"); if (username != "" && password != "" && name != "") { if (password.Equals(cpassword)) { //string syntax = "INSERT INTO AdminTable VALUES('" + username + "','" + password + "','" + name + "','" + phone + "');"; SqlCommand cmd = new SqlCommand("AdminTable_SP", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@password", password); cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@phone", phone); con.Open(); try { cmd.ExecuteReader(); MessageBox.Show("You're successfully registered"); } catch (Exception er) { MessageBox.Show("" + er); con.Close(); } con.Close(); } else { WrongInputLabel.Text = "Passwords do not match!"; WrongInputLabel.Show(); } } else { WrongInputLabel.Text = "Values cannot be empty!"; WrongInputLabel.Show(); } }
private void button1_Click(object sender, EventArgs e) { String Username, Password, tempP; Username = usernameField.Text; Password = passwordField.Text; try { con.Open(); String syntax = "SELECT password FROM AdminTable WHERE username='******'"; cmd = new SqlCommand(syntax, con); try { dr = cmd.ExecuteReader(); dr.Read(); } catch (Exception) { WrongInputLabel.Show(); con.Close(); } tempP = dr[0].ToString(); con.Close(); if (Password.Equals(tempP)) { MessageBox.Show("\tWelcome\n\t" + Username); this.Hide(); MainBody mb = new MainBody(); mb.Show(); } else { WrongInputLabel.Show(); con.Close(); } } catch (Exception) { WrongInputLabel.Show(); con.Close(); } }
private void textBox2_TextChanged(object sender, EventArgs e) { WrongInputLabel.Hide(); }
private void passwordField_MouseClick(object sender, MouseEventArgs e) { WrongInputLabel.Hide(); }
private void usernameField_MouseClick(object sender, MouseEventArgs e) { WrongInputLabel.Hide(); }