I have a method to return a query , but it is giving error.
Class Data.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;
}
}
UserID.cs class
#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.