aqiffm
(Aqiffm)
November 13, 2024, 7:15am
1
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”
aqiffm
(Aqiffm)
November 13, 2024, 7:30am
3
updated the original post
Yoichi
(Yoichi)
November 13, 2024, 7:45am
4
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,
aqiffm
(Aqiffm)
November 13, 2024, 7:59am
5
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
sudster
(Sudster)
November 13, 2024, 9:37am
6
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).
system
(system)
Closed
November 16, 2024, 9:38am
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.