DataTable distinctTable = dTable.DefaultView.ToTable(true,"ITEM_NO","ITEM_STOCK");
DataTable dtSummerized = new DataTable("SummerizedResult");
dtSummerized.Columns.Add("ITEM_NO",typeof(string));
dtSummerized.Columns.Add("ITEM_STOCK",typeof(double));
int count=0;
foreach(DataRow dRow in distinctTable.Rows)
{
count++;
//string itemNo = Convert.ToString(dRow[0]);
double TotalItem = Convert.ToDouble(dRow[1]);
string TotalStock = dTable.Compute("sum(" + TotalItem + ")", "ITEM_NO=" + dRow["ITEM_NO"].ToString()).ToString();
dtSummerized.Rows.Add(count,dRow["ITEM_NO"],TotalStock);
}
Error Message: Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier.
Do anyone can help me out?
Thanks.
You might try this:
dTable.Compute("sum([" + TotalItem + "])","");
I.e enclose your column name in square brackets [ ]
The idea is from this post.
The problem is exactly about your DataType of the column. If you have a row with dynamically added columns without DataType like that (it may be a result of a manual calculation or cross-tab query-like)
myTable.Columns.Add("AddedColumn");
You will probably face with the column conversion issue. Instead, If you change your add method with pointing DataType like below
myTable.Columns.Add("AddedColumn", typeof(System.Int32));
It will work I think. It's what I experienced & fixed before...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With