Summation of two columns using linq query

Hello Good People,

Need some help here.
Trying to add two columns in a datatable that caters for negative numbers as well but am stack with this error.

Assign: Input array is longer than the number of columns in this table.

That’s the query am trying to use.

(From d In dtIntRecRecon.AsEnumerable
Let s = {4,6}.Sum(Function (x) Convert.ToDouble(“0” & d(x).toString.Trim.Replace(",",".")))
Let ra = d.ItemArray.Take(2).Append(s).toArray
Select dtComputed.Rows.Add(ra)).CopyToDataTable

Got it from this post:

The error message is pretty clear. The number of items in your array of column values is more than the number of columns in the datatable.

we changed the strategy and inserted the need of defining the handling of non parseable values before implementation

1 Like

How did you implement the flow?

OP checks its own requirement and define what should happen with rows, where the values are not parseable (e.g. blanks, wrong formats)

Once this is cleared then the data will be checked for the format e.g. checking / reviewing samples

Based on this we can start with the solution option checks

1 Like

(From d In dtIntRecRecon.AsEnumerable
Let s = {4,6}.Sum(Function (x) if( d(x).toString.Trim=“”,CDbl(“0”),Convert.ToDouble(d(x).toString.Trim.Replace(“,”,“.”)))
Let ra = d.ItemArray.Take(2).Append(s).toArray
Select dtComputed.Rows.Add(ra)).CopyToDataTable

1 Like

When I supply the Take method with a zero instead of 2 it kind of does the job

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