Add new data column by combining other columns data using LINQ

I have a column A, B and C. I want to add a new data column called “Full Address”.

How can I do this using LINQ? where to add new data column and data contains combination of column A, B and C.

Refer to the image. Above is before, below is after. Actual data rows is huge, therefore wanted to use LINQ

Hi @aqiffm
Would you be able to share the sample values stored in column A, B, and C for the better understanding
also please share the expected output for “Full Address”

updated the original post

Hi,

We can achieve it using DataColumn.Expression as the following, for example.

dt.Columns("Full Address").Expression = "[A] +' '+ [B]+' '+[C]"

Sample
Sample20241113-4.zip (9.8 KB)

Or we can also achieve it using the following LINQ expression instead of the above

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

Regards,

I’ve tried the first method before! but i didnt add new data column bcs I assume the “.Expression” will add the new column for me. thank you!!

1 Like

Hi @aqiffm , I made a small change to @Yoichi 's solution, just in case you want to avoid using Excel (to make the process faster etc).

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