1
I am developing a query with C#, but I have a problem to accomplish it. I need to group by date.
Code:
public void BuscarVendaDeProdurtos_Saidas()
{
var data1 = Convert.ToDateTime(dateINI_Saida.Text);
var data2 = Convert.ToDateTime(dateFINI_Saida.Text);
var cod = Convert.ToInt64(textBox8.Text);
var pesquisa = from p in dc.ITEMVENDA
orderby p.CD_PRODUTO descending
where p.CD_PRODUTO == cod && p.Data_Venda >= data1 && p.Data_Venda <= data2
select new
{
p.NM_PROD,
p.Data_Venda,
p.QT_PRODV,
};
dataGridView2.DataSource = pesquisa.ToList();
Soma = 0;
foreach (DataGridViewRow dr in dataGridView2.Rows)
Soma += Convert.ToDecimal(dr.Cells[2].Value);
textBox12.Text = Convert.ToString(string.Format("{0:n}", Soma));
}
This research returns this:
Data Produto Qt
20/10/2017………………. 3
20/10/2017 …………….. 1
I need something like that:
Data Produto Qt
20/10/2017………………. 4
A single date already with its amounts summed.
I don’t understand c#, so I’m sorry if I talk nonsense, but is this data coming from a database? Why not use direct SQL, like
select data, count(*) from tabela group by data order by data
?– nunks