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 `userdetails` WHERE `username`=@username AND `password`=@pass"; command.CommandText = query; command.Connection = conn.getConnection(); command.Parameters.Add("@username", 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) { MessageBox.Show("Login Successful"); this.Hide(); MainForm mainForm = new MainForm(); mainForm.Show(); } else { if (textBoxUsername.Text.Trim().Equals("")) { MessageBox.Show("Enter your username"); } else if (textBoxPassword.Text.Trim().Equals("")) { MessageBox.Show("Enter your password"); } else { MessageBox.Show("Useranme/Password combination incorrect, Please try again."); } } }