Click to See Complete Forum and Search --> : Using aggregate function in Datatable select Method


pekellogg
March 14th, 2005, 05:01 PM
I'm searching for a way to place an aggregate function in the filter expression of the datatable's select method.

I thought the syntax would be something like

dim strexp as string
strexp = "MAX(columnName)"
foundrows as datarow()
foundrows = ds.tablename.select(strexp)

The error message indicates the filter expression 'MAX(columnName)' cannot be evaluated to a boolean expression.

Are aggregate expressions supported in the the select method? I searched the online docs without success.

Boumxyz2
March 15th, 2005, 07:31 AM
try

strexp = "Columname = Max(ColumnName)"

shelar_hemant
June 16th, 2008, 04:21 AM
Hi,
I am also facing the same proble. The said solution works for MAX function but it is not working for sum(ColumnName).

DataSet ds = RepeaterProductInfo.DataSource as DataSet;
DataRow [] row = ds.Tables[0].Select("Sum(ItemPrice)");
strReturnValue = row[0][0].ToString();

But it is throwing Exception {"Filter expression 'Sum(ItemPrice)' does not evaluate to a Boolean term." }


I also tried following code,

DataSet ds = RepeaterProductInfo.DataSource as DataSet;
DataRow [] row = ds.Tables[0].Select("ItemPrice = Sum(ItemPrice)");
strReturnValue = row[0][0].ToString();

When I try this statement was not able to calculate sum though DataTable contains data.

WillAtwell
June 16th, 2008, 07:39 AM
Just a guess here but have you tried using as in the select statement?

"Select Sum(ItemPrice) as TotalPrice"

HanneSThEGreaT
June 17th, 2008, 12:48 AM
shelar hemant, 2 things :
This thread is 3 years old, in future rather start your own thread.
It also looks like you are using C#, this is the VB.NET forum