0
I’m struggling to show the result of SUM in the DAO layer, the query brings the expected result, however, in the field where it is to show the sum, it does not show an error.
The process in Sql Server
ALTER PROCEDURE [dbo].[RelatorioDcv] @dateInicio date, @dataFim date
as
begin
select ve.Placa, sum(m.CombustivelAbastecido), count(v.VrId)
from Vr v inner join Mv m on
v.IdMv = m.Id inner join Veiculo ve on
v.IdVeiculo = ve.Id inner join Combustivel c on
ve.IdCombustivel = c.IdCombustivel
where convert(Date,v.DataEHoraServico) between @dateInicio and @dataFim
group by ve.Placa
end
the Code of the DAO:
public IList<Vr> Dcv(DateTime? dataInicio, DateTime? dataFim)
{
SqlCommand comando = new SqlCommand();
comando.CommandType = CommandType.Text;
comando.CommandText =
@"
EXECUTE RelatorioDcv @dateInicio=@dataInicio, @dataFim=@dataFim
";
comando.Parameters.AddWithValue("@dataInicio", dataInicio);
comando.Parameters.AddWithValue("@dataFim", dataFim);
SqlDataReader dr = Conexao.Selecionar(comando);
IList<Vr> lista = new List<Vr>();
MvDAO mdao = new MvDAO();
if (dr.HasRows)
{
while (dr.Read())
{
Combustivel comb = new Combustivel();
Vr vr = new Vr();
vr.Veiculo = new Veiculo();
vr.Mv = new Mv();
vr.Veiculo.Placa = Convert.ToString(dr["Placa"]);
vr.Mv.CombustivelAbastecido = Convert.ToDecimal(dr["CombustivelAbastecido"]);
lista.Add(vr);
}
}
else
{
lista = null;
}
dr.Close();
return lista;
}
The problem is precisely in this piece that theoretically was to show the sum
vr.Mv.CombustivelAbastecido = Convert.ToDecimal(dr["CombustivelAbastecido"]);
I didn’t try to show Count().
Rafael, what error appears, specifically?
– Rodrigo Tognin