1
Eae, guys! So... I’m pretty new to programming and I’m having some problems with the database login screen. The code does not give any error, but it is as if there was no user registration in 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 value variable does not change its value. I wonder if you could 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();
}
}
Thank you if you can help!!
Damn, man! Thank you so much! Somehow the other form I had created to register the user was adding space before the name, password and email because of my code. I’ve already arranged it here, I can’t believe I stayed 2 days on it, hahaha. Thank you very much, confrere!
– Oliver Gant