Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void CheckLogin()
- {
- try
- {
- //START OF SQL
- conn = new MySqlConnection(cs); // conn will now be equaled to a MysqlConnection with the String CS which is declared up above.
- string query = "SELECT * FROM accounts WHERE Username=@username AND Password=@password"; // Our query we are executing
- conn.Open(); // Opening the Database Connection
- MySqlCommand cmd = new MySqlCommand(query, conn); // Defining the MySQL Command
- cmd.Parameters.AddWithValue("@username", txtUsername.Text); // These two Make sure that the text fields add up with our queries
- cmd.Parameters.AddWithValue("@password", txtPass.Text);
- MySqlDataReader dr = cmd.ExecuteReader(); // This executes a reader to check if it all adds up
- if (dr.HasRows)
- {
- NotifyBox.Text = "SUCCESS: Logging in."; // Prints out Success message if succeeded then opens a new form and closes connection
- conn.Close();
- }
- else
- {
- NotifyBox.Text = "ERROR: Login Failed."; // Login has failed error message
- conn.Close();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("ERROR: " + ex.Message); // Catches the exception if there is one
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement