private void buttonLogin_Click(object sender, EventArgs e) { Connect connect = new Connect(); DataTable dataTable = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand(); string query = "SELECT * FROM `user` WHERE `username`=@usn AND `password`=@pass"; command.CommandText = query; command.Connection = connect.GetConnection(); command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = textBoxUsername.Text; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxPassword.Text; adapter.SelectCommand = command; adapter.Fill(dataTable); //if username and password exist if (dataTable.Rows.Count > 0) { this.Hide(); Main_Form main_Form = new Main_Form(); main_Form.Show(); //MessageBox.Show("YES"); } else { if (textBoxUsername.Text.Trim().Equals("")) { MessageBox.Show("Enter your username to login", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxPassword.Text.Trim().Equals("")) { MessageBox.Show("Enter your password to password", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Wrong username or password", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void buttonLogin_Click(object sender, EventArgs e) { CONNECT conn = new CONNECT(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand(); String query = "SELECT * FROM users WHERE username=@usn AND password=@pass;"; command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = textBoxUsername.Text; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxPassword.Text; command.CommandText = query; command.Connection = conn.getConnection(); adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { MessageBox.Show(textBoxUsername.Text.ToUpper() + " has logged in!"); this.Hide(); Main_Form main_Form = new Main_Form(); main_Form.Show(); } else { if (textBoxUsername.Text.Trim().Equals("")) { MessageBox.Show("Enter Username", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (textBoxPassword.Text.Trim().Equals("")) { MessageBox.Show("Enter Password", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Wrong Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnLogin_Click(object sender, EventArgs e) { CONNECT conn = new CONNECT(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand(); String query = "SELECT * FROM `user` WHERE `username`=@usn AND `password`=@pass"; command.CommandText = query; command.Connection = conn.getConnection(); command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = txtUsername.Text; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = txtPassword.Text; adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { this.Hide(); Main_Form mform = new Main_Form(); mform.Show(); } else { if (txtUsername.Text.Trim().Equals("")) { MessageBox.Show("Enter Your Username to Login", "Empty Username!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtPassword.Text.Trim().Equals("")) { MessageBox.Show("Enter Your Password to Login", "Empty Password!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("This Username or Password doesn't Exists.", "Invalid Data!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void buttonLogin_Click(object sender, EventArgs e) { Connect conn = new Connect(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand(); String query = "SELECT * FROM hotel_db.users WHERE username =@usn AND password=@pass"; command.CommandText = query; command.Connection = conn.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.Hide(); Main_Form mform = new Main_Form(); mform.Show(); } else { if (textBoxUsername.Text.Trim().Equals("")) { MessageBox.Show("Enter Your Username to Login", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxPassword.Text.Trim().Equals("")) { MessageBox.Show("Enter Your Paswword to Login", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("This Username or Password doesn't exists", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }