Hello All,
first off I'm using Visual Studio 2010, framework 4.0
What 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
1234 | 31224 | ROWA | 6020941N9999 | VLIES | 24875.17 | 1122011 | 800 | 40753 | 40759 | 40759 | 139 | PKGS | 3536 | FCL | 40370017 | 60282960 | MRKU 223 190-7 | 40FT | 0 |
1246 | 3… | ROWA | 6045999N | FLEECE |
| 1122011 | 5 | 40753 | 40759 | 40759 |
|
|
| FCL | 40370017 | 60282960 | MRKU 223 190-7 | 40FT | 0 |
1248 | 3… | KOSTAL IRELAND | 0277241AA | SEAT MEMORY | 12284.22 | 1122011 | 624 | 40750 | 40752 | 40760 | 1 | PAL | 167 | 1.123 | 80440792 | 90032500 | MSKU 041089-1 | 40FT | 0 |
1249 | 3… | KOSTAL IRELAND | 0277242AA | SEAT MEMORY |
| 1122011 | 390 | 40750 | 40752 | 40760 |
|
|
|
| 80440794 | 90032500 | MSKU 041089-1 | 40FT | 0 |
1250 | 3… | JOHNSON LAHNWERK | 6027134L | ZB STRUKTUR | 9377.94 | 1122011 | 432 | 40752 | 40756 | 40760 | 24 | PAL | 4464 | 28.759 | 21036789 | 1260135088 | MSKU 041089-1 | 40FT | 14.364 |
1251 | 3… | JOHNSON LAHNWERK | 6027126R | ZB STRUKTUR |
| 1122011 | 432 | 40752 | 40756 | 40760 |
|
|
|
| 21036789 | 1260135088 | MSKU 041089-1 | 40FT | 14.364 |
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 luck
Could 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 :(