Using aggregate function in Datatable select Method
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.
Re: Using aggregate function in Datatable select Method
try
strexp = "Columname = Max(ColumnName)"
Re: Using aggregate function in Datatable select Method
Hi,
I am also facing the same proble. The said solution works for MAX function but it is not working for sum(ColumnName).
Code:
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,
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.
Re: Using aggregate function in Datatable select Method
Just a guess here but have you tried using as in the select statement?
"Select Sum(ItemPrice) as TotalPrice"
Re: Using aggregate function in Datatable select Method
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