How to sum different cell values of a row in datatable

Hello All,

I want to sum 2nd cell and 4th cell and 6th cell value in the first row. Below is the screenshot for ref.


We can use for each loop but I want to use enumerable method or linq . Could any one help me on this

Hi @ushu

If you want only first row this enough will do,

cint(dt(0)(1).tostring) + cint(dt(0)(3).tostring) + cint(dt(0)(5).tostring)

This will sum 2nd,4th, and 6th columns of all rows,

dt1.AsEnumerable.Select(function(d) cint(d(1).ToString) + cint(d(3).ToString) + cint(d(5).ToString)).Sum




Thanks a tonn Prasath . It worked

1 Like


Some times there might be empty cells in the datatable. Then the above issue is coming

Capture (2)

Any suggestions on this please

I get it . We can use the below expression (cint or cdouble based on scenario)

cint(“0” & dt(0)(1).tostring) + cint(“0” & dt(0)(3).tostring) + cint(“0” & dt(0)(5).tostring)


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