DataTable dtStock = new DataTable();
DataColumn dcTotalCases = new DataColumn("TotalCases");
dcTotalCases.DataType = System.Type.GetType("System.Int32");
dcTotalCases.ReadOnly = false;
dtStock.Columns.Add(dcTotalCases);
Method 1
int sum = Convert.ToInt32(dtStock.Compute("Sum([TotalCases]) ", "[TotalCases] <> ''"));
When I use this method, I get an error
Invalid usage of aggregate function Sum() and Type: String.
Method 2
int sum = Convert.ToInt32(dtStock.Compute("SUM(Convert([TotalCases], 'System.Int32'))", "");
When I use this method, I get an error
Syntax error in aggregate argument: Expecting a single column argument
with possible ‘Child’ qualifier.
Please help me…
I believe method #1 should work – just don’t compare your
INTcolumn to an empty string!!So use something like this:
or
or whatever you need – just don’t use
[TotalCases] <> ''since that compares anINTto an empty string – and that’s not going to work!