Concat multiple column data into another column through linq

Hello All,

i want to add multiple column data into another column through linq.

Want to add Col1,Col2,Col4,Col5 into Col6

Input-
Col 1 Col2 Col3 Col4 Col5 Col6
aaaa bbbb cccc dddd eeee
123 456 789 123 456
Output-

Col 1 Col2 Col3 Col4 Col5 Col6
aaaa bbbb cccc dddd eeee aaaabbbbdddddeeee
123 456 789 123 456 123456123456

Please help me on that.

@rayan.jain7
Have a look here on how we can do it with the help of datacolumn expression. Has the benefit that it auto updates on value changes:

if LINQ is needed give a try on
work on datatable having structure Col1,Col5 - dtData
prepare empty datatable:
dtResult = dtData.Clone
Add Col6 to dtResult

LINQ

(From d in dtData.AsEnumerable
let c6 = String.Join(“”, {0,1,3,4}.Select(Function (x) d(x)))
let ra = d.ItemArray.Append(c6).toArray
Select dtResult.Rows.Add(ra)).CopyToDataTable

1 Like

Hi,

Can you try the following expression?

dt=dt.AsEnumerable.Select(Function(r) dt.Clone.LoadDataRow({r(0),r(1),r(2),r(3),r(4),r(0).ToString+r(1).ToString+r(2).ToString+r(3).ToString+r(4).ToString},False)).CopyToDataTable

Main.xaml (7.8 KB)

Regards,

2 Likes

assuming your datatable variable is called dt
a. use add data column activity to add data column called Col6 (if it doesnt exist)
b. use invoke code
click edit arguments and add in/out argument dt

then click edit code and paste this

dt.AsEnumerable().ToList().ForEach(Sub(row) row("Col6")= row("Col1").ToString+row("Col2").ToString+row("Col4").ToString+row("Col5").ToString)

this will set Col6 = col1+col2+col4+col5

2 Likes