I am banging my head again, and appologise if such a qestion has been posted and answered - i searched and could not see any results matching my question.
I have a datagridview1 full of data, one column has a date and another a qty.

datagridview1

Date         Qty
2015-11-05 | 44
2015-11-09 | 12
2015-12-04 | 100
2016-01-15 | 10
2016-01-26 | 15

My loop takes too long to add up the Qtys by month and year. esp when the file is 2mb or more. SO my idea is to put the data into a datatable andquery it from there.
it looks something like this ... lol ... dont laugh please.

dim total as integer
total =0

do until datagridview1 rows = 0

     if datagridvied cell 0,0 = datagridview cell 1,0 then 

        total = total + datagridvied cell 0,1 value
        delete current line in datagridview 1

     else

      put new line in new datagrid2
      delete current line in datagridview 1
      make total 0

     end if
loop

It takes too long to run when the data is more than 2mb .. so I decided to put all the data I got from a text file into a table and just use a SQL Query, then show the result of that query in new datagrid2, I stated the code like this:

Dim dt As New DataTable
    With dt
        .Columns.Add("UDate")
        .Columns.Add("Qty")
    End With

    For Each dr As DataGridViewRow In Me.DataGridview1.Rows
        dt.Rows.Add(dr.Cells("UDate").Value, dr.Cells("Qty").Value)
    Next

so my datatable dt is now filled with the data from datagridview1 (I am guessing there is no way of putting the "summed" data only into the datatable)

Result should be:

Datagridview2 (data from dataable dt)

YearMnth  Qty
2015-11 | 56
2015-12 | 100
2016-01 | 25

My code to sum the data with SQL statement then display it in my datagridview2 is not working and Im not even going to post it here ... lol
Pelase I know there is some of you that think this is silly and sooo easy. please point me in the direction to solve this.
Thanx !

Take a moment and post how you solved this. I was going to comment why I thought the code was slow. Deleting rows like that would be sluggish.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.