Exemple #1
0
        private void buttonlogin_Click(object sender, EventArgs e)
        {
            MY_DB db = new MY_DB();

            MySqlDataAdapter adapter = new MySqlDataAdapter();
            DataTable        table   = new DataTable();
            MySqlCommand     command = new MySqlCommand("SELECT * FROM `users` WHERE `username` = @usn AND `password`= @pass", db.getConnection);

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value  = textBoxusername.Text;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxpassword.Text;

            adapter.SelectCommand = command;

            adapter.Fill(table);

            if (table.Rows.Count > 0)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("Invalid username or password", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }