Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button1_Click(object sender, EventArgs e)
- {
- //sql query
- MySqlConnection conn;
- MySqlDataAdapter da = new MySqlDataAdapter();
- String sqlquery = "SELECT ID, username, password, banned FROM users Where username='" + textBox1.Text + "' and password='" + textBox2.Text + "'";
- MySqlCommand myCommand = new MySqlCommand();
- //connect to DB
- conn = new MySqlConnection();
- conn.ConnectionString = "server=127.0.0.1; uid=root; password=password; database=osssx;";
- //see if connection failed.
- try
- {
- conn.Open();
- }
- catch (MySqlException myerror)
- {
- MessageBox.Show("Error Connecting to Database: " + myerror.Message);
- this.Close();
- }
- myCommand.Connection = conn;
- myCommand.CommandText = sqlquery;
- //start query
- da.SelectCommand = myCommand;
- MySqlDataReader myData;
- myData = myCommand.ExecuteReader();
- //see if user exits.
- {
- if (myData.HasRows)
- {
- MessageBox.Show("Valid Login Details", "Accepted", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- myData.Close();
- MySqlDataReader myReader;
- myReader = myCommand.ExecuteReader();
- while (myReader.Read())
- {
- ID = myReader.GetInt32(1);
- ID2 = myReader.GetString(1);
- }
- myReader.Close();
- Form2 main = new Form2();
- main.Show();
- this.Hide();
- }//if not close connection
- else
- {
- conn.Close();
- MessageBox.Show("Invalid Login Details, Retry?", "Login Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
- textBox1.Text = "";
- textBox2.Text = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement