VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,768 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hi .Transpose data From Columns to Rows in Table .thank
Dim MyDataTable As New DataTable
Dim OnlyColumns as String()={"Type","Location","Size"}
MyDataTable.Columns.Add("Group")
MyDataTable.Columns.Add("Type")
MyDataTable.Columns.Add("Size")
MyDataTable.Columns.Add("Location")
MyDataTable.Rows.Add({"CABLE", "MV", "1x240", "Air Building"})
MyDataTable.Rows.Add({"CABLE", "MV", "1x240", "ACC Building"})
MyDataTable.Rows.Add({"CABLE", "LV", "1x240", "Swithgear"})
MyDataTable.Rows.Add({"Install", "Cable Tray", "20", "Swithgear"})
Dim ResultArray as String()'Need Linq Command to:
ResultArray(0)="0,Type,MV,LV,Cable Tray"
ResultArray(1)="1,Location,Air Building,ACC Building,Swithgear"
ResultArray(2)="2,Size,1x240,20"
```
Hi @Mansour_Dalir ,
You can refer to the following code.
Dim ResultArray As String() = Enumerable.Range(0, MyDataTable.Columns.Count) _
.Select(Function(index) index & "," & MyDataTable.Columns(index).ColumnName & "," & String.Join(",", MyDataTable.AsEnumerable().Select(Function(row) row(index).ToString()).Distinct())) _
.ToArray()
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.