I have DataReader
on my website to read the data the bank brings. I have a problem with VS, but I do not know how to do it.
There is already an open DataReader associated with this Command that must be closed first
Would there be anything that could change for several people to access at the same time? Close DataReader?
public static List<dMovimentoUser> listar_lancamentos(string conexao)
{
List<dMovimentoUser> carrinho = new List<dMovimentoUser>();
Dados objDados = new Dados();
SqlCommand command = new SqlCommand("usp_lancamentos_internos_listar", objDados.abreConexao());
command.Parameters.AddWithValue("@conexao", conexao);
command.CommandType = CommandType.StoredProcedure;
SqlDataReader reader;
reader = command.ExecuteReader();
objDados.abreConexao();
try
{
while (reader.Read())
{
dMovimentoUser ct = new dMovimentoUser();
ct.codigo = reader["código"].ToString();
ct.descricao = reader["produto"].ToString();
ct.data = reader["data"].ToString();
ct.hora = reader["hora"].ToString();
ct.operacao = reader["operacao"].ToString();
ct.qtd = float.Parse(reader["quantidade"].ToString());
ct.historico = reader["historico"].ToString();
carrinho.Add(ct);
}
return carrinho;
}
catch (Exception ex)
{
throw new Exception("Erro encontrado: " + ex.Message);
}
finally
{
reader.Close();
objDados.fechaConexao();
}
}