Hello,
I have a DataTable like this :
I need to merge the values of the first 2 rows of each column and set the result value as header.
Do you have any suggestions for this issue?
Thanks in advance.
Hello,
I have a DataTable like this :
I need to merge the values of the first 2 rows of each column and set the result value as header.
Do you have any suggestions for this issue?
Thanks in advance.
Hello @SONYC
Assign activity:
dtResult = New DataTable
For Each activity (ForEach col in dt.Columns):
a. Assign activity:
dtResult.Columns.Add(col.ColumnName, GetType(String))
dtResult.Rows.Add(dt.Rows(0)(col.ColumnName).ToString & " " & dt.Rows(1)(col.ColumnName).ToString)
Remove Data Rows activity (for removing the first two rows from the original DataTable):
DataTable: dt
Index: 1
Number of Rows: 2
Invoke Method activity:
TargetObject: dt
MethodName: Merge
Parameters: dtResult
Thanks & Cheers!!!
Thank you @Yoichi
It works exactly as expected.
Just for information, what would be the lambda query for this procedure in one shot ?
With LINQ the constraint would be to use a second DT I guess.
Hi,
It’s necessary 2 expressions. Can you try the following sample?
Dim d As DataTable = dt
dt.Columns.Cast(Of DataColumn).ToList().ForEach(Sub(c)
c.ColumnName = d.Rows(0).Item(c).ToString()+" "+d.Rows(1).Item(c).ToString()
End Sub
)
dt = dt.AsEnumerable.Skip(2).CopyToDataTable()
Sample
Sample20231205-1Lv2.zip (8.7 KB)
Regards,
Again, thank you @Yoichi !
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.