Hey, everyone! So ... I'm really new to programming and I'm having problems with the login screen with database. The code does not give any error, but it is as if there was no user registration in the SQL server, I tried all 5 entries that exist and nothing, I only get the message that the data is incorrect, it seems that the variable value does not change its value. Could you help me?!
public void Logar()
{
string con = " server = DESKTOP-6BAVUH0; Database = Cadastro; Trusted_Connection = true";
SqlConnection Conex = new SqlConnection(con);
string coman = @"SELECT Count (*) FROM usuario WHERE Login = @nome AND Senha = @password AND [E-mail] = @email" ;
string nome= textBox1.Text, password = textBox2.Text, email = textBox3.Text ;
try
{
SqlCommand comando = new SqlCommand(coman, Conex);
comando.Parameters.AddWithValue("@nome",nome);
comando.Parameters.AddWithValue("@password",password);
comando.Parameters.AddWithValue("@email", email);
Conex.Open();
int valor = (int)comando.ExecuteScalar();
if (valor > 0)
{
Logado = true;
MessageBox.Show("Logado com sucesso. Sejam bem-vindo!");
this.Close();
}
else
{
Logado = false;
MessageBox.Show("Dados incorretos!");
}
}
catch (SqlException erro)
{
MessageBox.Show(erro + "Na conexão com o banco de dados");
}
finally
{
Conex.Close();
}
}
Grateful if you can help !!