Results 1 to 3 of 3

Thread: sum column based on date on Datagridview

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    36

    sum column based on date on Datagridview

    Hy, I need a help on this, I have a datagridview with several columns, but what I´m trying to do is sum km2 column based on date. I´m using the following code:

    Code:
        Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Me.CadastroSeqTableAdapter.Fill(Me.Db01DataSet.CadastroSeq)
    
    	Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\db01.mdb")
            Dim ds As New DataSet
            Dim da As OleDb.OleDbDataAdapter
            Dim sql As String
    
            sql = "SELECT Data, Sum(Km2_FF) FROM CadastroSeq GROUP BY Data"
            da = New OleDbDataAdapter(sql, con)
    
            Dim dt As New DataTable("CadastroSeq")
    
            da.Fill(dt)
            CadastroSeqDataGridView.DataSource = dt
    
        End Sub
    The query is grouping by DATE (data), this OK, but the km2_FF values not, is not showing anything. Do you guys have a different solution or to fix this one?
    To be more clearer, this datagridview has different values of km2_FF for the same date, I want to display the total of km2_FF for each day.
    Thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: sum column based on date on Datagridview

    That SQL is going to group records where Data is the same. If records aren't grouped then that would suggest that Data is not the same. Is it maybe that the dates are the same but they all have different times?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    36

    Re: sum column based on date on Datagridview

    The SQL is grouping the date records, but the km2 is not summing. All the Dates have the same time (00:00:00).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width