I have a dataset which includes some numbers, I want to calculate the sum of the difference in the numbers how do I do this?
For example my dataset looks like this:
Name Score
Luke 100
Adam 90
James 80
Peter 70
Mike 60
How do I calculate the sum of the difference within a “for loop” in vb.net such that it does something like this below:
(100 – 90) + (90 – 80) + (80 – 70) + (70 – 60) = 40
I tried to do this below, but i am not sure of how to add the difference:
Dim i as integer
For i = 0 to ds.tables(0).rows.count
ds.tables(0).Row(i).Item(1)
Dim diff = ds.tables(0).Row(i).Item(1) - ds.tables(0).Row(i+1).Item(1)
sum = ....
Next
Any help will be appreciated
You can try this,
You can use totalValue as your answer