Use "SUM" in access + vb.net

1

I have a small problem in the Access query, where I have the following code:

 Dim cn As New OleDb.OleDbConnection
    Dim cmd As New OleDb.OleDbCommand
    Dim Da As New OleDb.OleDbDataAdapter
    Dim Dt As New DataTable
    Dim dtinicio As String
    Dim dtfim As String
    Dim NO As String
    dtinicio = txtDt1.Text
    dtfim = txtDt2.Text()
    NO = TextBox1.Text
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Firebird.mdb"
    cn.Open()
    txtDt1.Text = CDate(txtDt1.Text).ToString("dd/MM/yyyy")
    txtDt2.Text = CDate(txtDt2.Text).ToString("dd/MM/yyyy")
    Try
        With cmd
            .CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@dtInicio", dtinicio)
            cmd.Parameters.AddWithValue("@dtFim", dtfim)
            .CommandText = "SELECT dt , SUM(UNI) AS UNI FROM RELATORI WHERE dt between @dtInicio and @dtFim ORDER BY dt  ORDER BY dt"
             .Connection = cn
        End With
        With Da
            .SelectCommand = cmd
            Dt = New DataTable
            .Fill(Dt)
            RELATORIDataGridView.DataSource = Dt
        End With
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    cmd.Parameters.Clear()
    cmd.Parameters.Clear()

What I need, would be to include in the line:

.CommandText = "SELECT dt , SUM(UNI) AS UNI FROM RELATORI WHERE dt between @dtInicio and @dtFim ORDER BY dt  ORDER BY dt"

plus some fields with SUM, in case 3 more. I could not find a way to insert the other fields that in the case would be "SALE", "GROUP", "CUPOM". Would someone have an example of how I do this?

    
asked by anonymous 01.07.2015 / 21:17

1 answer

0

There is not much secret:

.CommandText = @"SELECT dt, GRUPO, SUM(UNI) AS UNI, SUM(VENDA) as Vendas, SUM(CUPOM) as Cupons
         FROM RELATORI 
         WHERE dt between @dtInicio and @dtFim 
         GROUP BY dt, Grupo
         ORDER BY dt"
    
01.07.2015 / 21:36