How to perform Addition of all the integers in Cash In, On-Us Check and Not On-Us Check?

Hello Everyone, a little help plz.
I need to add all the integers under three columns and output it on the next right cell (or maybe into a variable) or somewthing.

Is it possible to perform this any easier way, or looping is the only option?
Thanks.

when we can rely on the column values / formats

with details:

Hi @Shahabaz

Try this

DataTable.AsEnumerable().Sum(Function(row) row.Field(Of Int32)("Cash In")).ToString

DataTable.AsEnumerable().Sum(Function(row) row.Field(Of Int32)("On-Us Check")).ToString

DataTable.AsEnumerable().Sum(Function(row) row.Field(Of Int32)("Not On-Us Check")).ToString

Hi @lrtetala ,

It does work, but I’m having minor issues regarding the conversion of Double to Int32. I will be digging a bit for the post by @ppr and will update accordingly.

Thanks.
Shahabaz P. L

Can you try to change from Int32 to Double

DataTable.AsEnumerable().Sum(Function(row) row.Field(Of Double)(“Cash In”)).ToString

Hi @lrtetala

It worked. And makes sense too.

Thanking,
Shahabaz P. L

1 Like

from the LINQ tutorial, a sample already converting to doubles and handling non parseable values with a default 0

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.