Tanx jmcilhinney for your advice. And tanx Herman for your suggestion.
I study the code again through all night, tested all possible solution and got it solved.
Finally, i used LINQ to perform the group and summation and it works. Tanx all for your support :)
sir, can you please show me the example on how to loop through the rows and add the data to a Dictionary?
What am i confused is, in the first step in post #2 which is to loop through the rows and add the data to a Dictionary , i should declare the type of DURATION as what? if you refer to #7...
Or maybe i should use FOR EACH selected LINE, i sum the DURATION for the line and loop it to the next LINE?
but i'm not sure how to do the loop to get each line and sum the DURATION by LINE.
I know how to do the conversion from string to timespan type and sum it in vb.
The problem is, i got the total of summation for the whole of DURATION column. Not sum by group (LINE).
Do you have any idea how i can sum it by group?
ok. So first i dont have to convert the DURATION of type Char to timespan?
I just insert straight from database to the dataset without converting it?
Is that so?
Sir, can you please show example please...
Now i'm trying to do the Dictionary method and get error "an item with the same key has already been added"
Here is the code:
Dim dct As New Dictionary (Of String, String)
For each r As Datarow In Ds.Tables(0).Rows
dct.Add(r.Item(1).ToString(), r.Item(0).ToString())
Next
Another...
jmcilhinney, tanx for your reply.
However, I'm not familiar with DICTIONARY and have tried doing the summation using LINQ (just learn about LINQ yesterday).
So far here is what i've done:
Dim totalSum As Datatable = Ds.Table(0)
Dim query = _
From s In totalSum.AsEnumerable() _
Let line =...
Hi, i'm a newbie and get stuck with this problem for a few days.
I have datatable with two column, line and duration.
I want to sum the duration based on the line group. For example:
LINE
DURATION
A1
00:05:20
A1
00:07:00
A1
00:02:10
A1
00:01:50
A2
00:02:01
A2
00:03:45...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.