Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier

Tags:

c#

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.

like image 845
Rushabh Avatar asked Apr 12 '11 15:04

Rushabh


2 Answers

You might try this:

dTable.Compute("sum([" + TotalItem + "])","");

I.e enclose your column name in square brackets [ ]

The idea is from this post.

like image 76
Buggy Avatar answered Nov 15 '22 00:11

Buggy


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...

like image 27
acik-pozisyon Avatar answered Nov 15 '22 02:11

acik-pozisyon