DataSet sum

A

amarrr

Hi,
I have just started working with ADO.NET and VB.NET and have a
question.
I have dataset with tables..
This table contains a 4 column called ID,name,IDacc,price. How can I
sum value in columns price where values in columns IDacc is equal....
For example. in table I have somthing like this.
ID name IDacc price
1 ak 2 26
2 zk 2 14
3 fh 3 13
and i try to have new DS.tables with this
numElements sum
2 40
1 13
I know It would be better to do calculation in the stored procedure or
inline SQL statmens that returns the result sets to the datatables, but
in this case i cant do that....

TnX...
 
A

amarrr

Miha Markic [MVP C#] je napisao:
Hi there,

See DataTable.Compute method.
Tnx Miha....
I try this
total = ds.Tables("printS").Compute("Sum(iznos)", "TID = ' 6' "), but
I have this error: Invalid usage of aggregate function Sum() and Type:
String,
because in my dataset and table this columns has type of string.... I
fill this data set from another data set, and this column in SQL
serever has type of money... How can I preserve data type through data
set, or how i Can set data type for this column in data set, any
example or tutorial is welcome....
I try this, to change data type,
For i As Integer = 0 To ds.Tables("printSpojeni").Rows.Count - 1
ds.Tables("printS").Rows(i).Item("iznos") =
CType(ds.Tables("krajnjiDS").Rows(i).Item("iznos"), Decimal)
Next

but dont work....
 
A

amarrr

Miha Markic [MVP C#] je napisao:
Hi there,

See DataTable.Compute method.
Tnx Miha....
I try this
total = ds.Tables("printS").Compute("Sum(iznos)", "TID = ' 6' "), but
I have this error: Invalid usage of aggregate function Sum() and Type:
String,
because in my dataset and table this columns has type of string.... I
fill this data set from another data set, and this column in SQL
serever has type of money... How can I preserve data type through data
set, or how i Can set data type for this column in data set, any
example or tutorial is welcome....
I try this, to change data type,
For i As Integer = 0 To ds.Tables("printSpojeni").Rows.Count - 1
ds.Tables("printS").Rows(i).Item("iznos") =
CType(ds.Tables("krajnjiDS").Rows(i).Item("iznos"), Decimal)
Next

but dont work....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top