Skip to content

Instantly share code, notes, and snippets.

@metinsaylan
Created June 27, 2016 11:59
Show Gist options
  • Save metinsaylan/642f091ba7902d323717e1c8bc6f8d0f to your computer and use it in GitHub Desktop.
Save metinsaylan/642f091ba7902d323717e1c8bc6f8d0f to your computer and use it in GitHub Desktop.
Rotate DataTable
Public Shared Function RotateTable(dt As DataTable) As DataTable
Dim dt2 As New DataTable()
For i As Integer = 0 To dt.Rows.Count
dt2.Columns.Add()
Next
For i As Integer = 0 To dt.Columns.Count - 1
dt2.Rows.Add()
dt2.Rows(i)(0) = dt.Columns(i).ColumnName
Next
For i As Integer = 0 To dt.Columns.Count - 1
For j As Integer = 0 To dt.Rows.Count - 1
dt2.Rows(i)(j + 1) = dt.Rows(j)(i)
Next
Next
Return dt2
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment