dataset and group by

  • Thread starter Thread starter giminera
  • Start date Start date
G

giminera

I've got a dataset on a datagridview: fileds are
code,descr,price,vatcode. I have to calculate the total amount of
vat.
Example:
first row = price 10$, vatcode 20
second row = price 50$, vatcode 10
third row = price 10$, vatcode 20
So, I have a SQL Table with vatcode and vat%, for example vatcode 20 =
20%, vatcode 10 = 10%
The goal is to group the rows of dataset (datagridview) by the vatcode
and calculate the total price for every different vatcode, for
example:
amount of 20$ (sum of first and third rows) with vatcode 20.
amount of 50 with vatcode 10 (the only one in the datagrid with that
vatcode).
After I have to calculate the entire amount of vat, so I have 20$ at
20% and 50$ at 10% and put it into a variable.
Thanks.
George
 
I've got a dataset on a datagridview: fileds are
code,descr,price,vatcode. I have to calculate the total amount of
vat.
Example:
first row = price 10$, vatcode 20
second row = price 50$, vatcode 10
third row = price 10$, vatcode 20
So, I have a SQL Table with vatcode and vat%, for example vatcode 20 =
20%, vatcode 10 = 10%
The goal is to group the rows of dataset (datagridview) by the vatcode
and calculate the total price for every different vatcode, for
example:
amount of 20$ (sum of first and third rows) with vatcode 20.
amount of 50 with vatcode 10 (the only one in the datagrid with that
vatcode).
After I have to calculate the entire amount of vat, so I have 20$ at
20% and 50$ at 10% and put it into a variable.
Thanks.
George

Maybe you can save the values in an array:

Dim myArr() As Integer
Dim vatcode As Integer
ReDim myArr(0)

For row As Integer = 0 To DataGridView1.Rows.Count - 2
vatcode = DataGridView1.Item("vatcode", row).Value
If myArr.Length < vatcode Then
ReDim Preserve myArr(vatcode)
End If
myArr(vatcode) += DataGridView1.Item("price", row).Value
Next

and now, for every vatcode you have a cell in the array containing the
price summary.
 
Back
Top