1
public String IdentificarAcessoDAL(FuncionarioDTO acesso)
{
try
{
conexao.cmd.Connection = conexao.conexao;
string recuperar = "SELECT CARGO.NOME_CARGO FROM LOGIN INNER JOIN FUNCIONARIO ON FUNCIONARIO.CPF_FUNCIONARIO = LOGIN.CPF_FUNCIONARIO INNER JOIN CARGO ON CARGO.ID_CARGO = FUNCIONARIO.ID_CARGO WHERE LOGIN.USUARIO_LOGIN = '" + acesso.User + "' AND LOGIN.SENHA_LOGIN = '" + acesso.Password + "'";
conexao.cmd.CommandText = recuperar;
conexao.conexao.Open();
return funcionarioDTO.Funcao = conexao.cmd.ExecuteScalar().ToString();
}
catch (Exception erro)
{
throw erro;
}
finally
{
conexao.conexao.Close();
}
}
Whenever I enter the correct information it executes the application perfectly, but when it does not find in the database, it simply stops the execution of the program and displays the following error:
The program seeks the position of the employee, and for this it uses the login and the password, and this error only appears when the login and/or password are incorrect, otherwise it works perfectly.
When the exception occurs, what are the values of
conexao.conexao
,acesso.User
andacesso.Password
? In fact, I kick that at that moment the objectacesso
is not set. You can also reschedule commandstry
/catch
to see exactly in which line the exception occurs.– Pedro Gaspar
In the Connection class "public Mysqlconnectionconnection = new Mysqlconnection(@"server=179.188.16.199;database=oticabd;Uid=oticabd;Pwd=senha123;");" and in the Funciodal class " Connectionconnection = new Connection(); ", how is access not set? they receive the value of Textbox’s, everything occurs correctly when the value is typed and equal to the ones in the database, when it does not find, it starts to give this problem
– Stephan Carvalho