I have the following method (below), which throws this error: "Arithmetic operation resulted in an overflow". The table contains 192526 rows and 9 columns.
Is there a way to place a breakpoint for each item inside the "dt.Rows.Add()"? I.e. can I define which Row and which Column this is failing on, etc?
I could do a "StepInto" once I reach this line. And I saw this error "error CS0103: The name 'dt' does not exist in the current context" (I assume that is not the one that is causing the eventual failure), in the line "dt.AsEnumerable().Sum(dr => dr.Field("Balance"))," But - there are way too many entries to do "StepOver" for each, and before it gets into next one.
public DataTable AddTrailer(DataTable dt)
{
try
{
if (dt.TableName.Equals("Summary"))
{
Console.WriteLine("Summary Table");
dt.Rows.Add(
null,
null,
null,
null,
null,
null,
dt.AsEnumerable().Sum(dr => dr.Field<int>("Balance")),
dt.AsEnumerable().Sum(dr => dr.Field<int>("Total1")),
dt.AsEnumerable().Sum(dr => dr.Field<int>("Total2"))
);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception thrown in the AddTrailer - Summary");
throw;
}
return dt;
}
If I use the suggestion as "dt.AsEnumerable().Sum(dr => (long)dr.Field("Balance"))" - I will get another error: "{"Value was either too large or too small for an Int32.Couldn't store <21488943305> in Balance|Current Balance Column. Expected type is Int32."}"
I cannot even figure out why it is complaining as the number of rows (or rows * columns) should not be that high (to be outside of the regular int).