0
I have a method to return a query, but it’s going wrong.
Data Class.Cs:
public static SqlDataReader retornaQuery(SqlCommand query, List<SqlParameter> parameters)
{
try
{
//Instância o sqlcommand com a query sql que será executada e a conexão.
SqlCommand comando = new SqlCommand(query.CommandText, connection());
if (parameters != null && parameters.Count > 0)
{
comando.Parameters.AddRange(parameters.ToArray());
}
//Executa a query sql.
var retornaQuery = comando.ExecuteReader(); //Procedure or function 'SP_AUTENTICAR_USUARIOS' expects parameter '@USUARIO', which was not supplied.
//Fecha a conexão.
connection().Close();
//Retorna o dataReader com o resultado
return retornaQuery;
}
catch (SqlException ex)
{
throw ex;
}
}
User class.Cs
#region Parâmetros
private const String PARAM_USU_ID = "ID";
private const String PARAM_USU_USUARIO = "USUARIO";
private const String PARAM_USU_SENHA = "SENHA";
#endregion
#region Procedures
private const String PROCEDURE_SP_LISTAR_USUARIOS = "SP_LISTAR_USUARIOS";
private const String PROCEDURE_SP_AUTENTICAR_USUARIOS = "SP_AUTENTICAR_USUARIOS";
#endregion
public Boolean Autenticar(Usuario usuario)
{
try
{
var cmd = new SqlCommand();
var parameters = new List<SqlParameter>();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = PROCEDURE_SP_AUTENTICAR_USUARIOS;
parameters.Add(new SqlParameter() { ParameterName = PARAM_USU_SENHA, Value = usuario.UsuSenha, SqlDbType = SqlDbType.VarChar});
parameters.Add(new SqlParameter() { ParameterName = PARAM_USU_USUARIO, Value = usuario.UsuUsuario, SqlDbType = SqlDbType.VarChar });
using (IDataReader idr = Dados.retornaQuery(cmd, parameters))
{
while (idr.Read())
{
if (idr["MSG"].Equals("1"))
{
return true;
}
return false;
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return false;
}
Error: Procedure or Function 'SP_AUTENTICAR_USUARIOS' expects Parameter '@USUARIO', which was not supplied.
As step the value of the parameter?
– Leonardo
Where has the line: Parameters.Add(new Sqlparameter() { Parametername = "ID"}); Puts a comma , has a property Value, then you put the value.
– odairsk8
Okay, but there’s another mistake:
Procedure or function 'SP_AUTENTICAR_USUARIOS' expects parameter '@USUARIO', which was not supplied.
; Since I am passing the parameter. I will update my question for you to see– Leonardo
Updated question!
– Leonardo
Missing command type kkk
– Leonardo