PC Review


Reply
Thread Tools Rate Thread

dataset and group by

 
 
giminera
Guest
Posts: n/a
 
      14th Feb 2007
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

 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      15th Feb 2007
Giminera,

Do you know the method to add columns to your datatable while using
expressions and to vertical sum while using compute.



http://msdn2.microsoft.com/en-gb/lib...e.compute.aspx

http://msdn2.microsoft.com/en-gb/library/system.data.datacolumn.expression(VS.80).aspx

As long as you don't force it, will those columns not come in your database.

Cor


"giminera" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Tamir Jacob
Guest
Posts: n/a
 
      15th Feb 2007
On Feb 14, 10:10 pm, "giminera" <gimin...@libero.it> wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
group by in dataset tshad Microsoft C# .NET 2 23rd Apr 2009 05:53 PM
Re: group by in dataset sloan Microsoft C# .NET 0 23rd Apr 2009 02:21 AM
group dataset =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?= Microsoft ASP .NET 4 2nd Oct 2006 07:23 PM
Is it possible to group data in a dataset? Amadelle Microsoft C# .NET 5 26th May 2004 08:37 PM
Query Group Dataset Chris Thunell Microsoft VB .NET 1 28th Oct 2003 05:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:55 AM.