Home All Groups Group Topic Archive Search About
Author
26 Oct 2006 12:29 PM
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...

Author
26 Oct 2006 1:12 PM
Miha Markic [MVP C#]
Hi there,

See DataTable.Compute method.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<ama***@gmail.com> wrote in message
Show quote
news:1161865770.051997.290680@m73g2000cwd.googlegroups.com...
> 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...
>
Author
31 Oct 2006 12:57 PM
amarrr
Miha Markic [MVP C#] je napisao:
> Hi there,
>
> See DataTable.Compute method.
>
> --
> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
> RightHand .NET consulting & development www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>
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....
Author
31 Oct 2006 1:00 PM
amarrr
Miha Markic [MVP C#] je napisao:
> Hi there,
>
> See DataTable.Compute method.
>
> --
> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
> RightHand .NET consulting & development www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>
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....

AddThis Social Bookmark Button