Hello All,first off I'm using Visual Studio 2010, framework 4.0What am I trying to achieve:well, I'm getting info from my SQL database and put it into a DataTable, I then need to do a calculation PER ROW so I add another column to my datatable (ColumnV - datatype = decimal)here is a sample of what my data looks like: Last Column = ColumnV
0
All good and well but now for my next challenge - I need to add another column to my datatable - and ONLY write to it once the value of the container change (3rd last column with values e.g. MSKU 041089-1)with the below code i tried to achieve this - but NO luckCould you please spare me some of your time and help me out with my issue:
public System.Data.DataTable Calc(System.Data.DataTable ACTable) { string i_sGroupByColumn = "CONTAINER";
//adding column for the row count ACTable.Columns.Add("Results", typeof(decimal));
//looping thru distinct values for the group, counting foreach (DataRow dr in ACTable.Rows) { for (int i = 0; i < ACTable.Rows.Count; i++) { System.Data.DataTable dtContainer = new System.Data.DataTable(); dtContainer = GetData.GetContainerSize(ACTable.Rows[i]["Type"].ToString()); decimal dContainerSize = Convert.ToDecimal(dtContainer.Rows[0]["Container_Size"].ToString());
string cExpr = "SUM(CONVERT(ColumnV, 'System.Decimal'))"; string cCond = i_sGroupByColumn + " = '" + dr[i_sGroupByColumn] + "'";
decimal dSumVal = (decimal)(ACTable.Compute(cExpr, cCond)); dr["Results"] = dSumVal / dContainerSize; } } return ACTable; }
currently its bombing out on: decimal dSumVal = (decimal)(ACTable.Compute(cExpr, cCond));with error:
Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier.
Please please please - i need to have this project done by 5th December :(