I'm not able to do a check in the database, to make sure the user exists. Here is the code:
private void button1_Click_1(object sender, EventArgs e)
{
string conexao = "SERVER = localhost; DATABASE = dizimistas; UID = root; PASSWORD = senha00789;";
string query = "SELECT idusuario FROM USUARIOS WHERE nomeusuario = @usuario and senhausuario = @senha;";
using (MySqlConnection objConexao = new MySqlConnection(conexao))
{
objConexao.Open();
try
{
MySqlCommand command = new MySqlCommand(query, objConexao);
command.Parameters.AddWithValue("@usuario", txtUsuario);
command.Parameters.AddWithValue("@senha", txtSenha);
int? id = (int?)command.ExecuteScalar();
if (id.HasValue)
{
FormPrincipal form = new FormPrincipal();
form.Show();
} else
{
MessageBox.Show("Usuário ou senha inválidos!");
}
}
finally
{
objConexao.Close();
}
}
}
If the query returns true (User exists), then it will be taken to another form. But everything I put in this IF, visual studio does not accept.