Rotate Data table

Private Function RotateDataTable(ByVal dt As DataTable) As DataTable   Dim dtNew As New DataTable
'for each row, create a column
For i As Integer = 0 To dt.Rows.Count() - 1
Dim dc As New DataColumn(dt.Rows(i)(0))
dtNew.Columns.Add(dc)
Next
'for each column, create a row
For j As Integer = 1 To dt.Columns.Count() - 1
Dim dr As DataRow
dr = dtNew.NewRow()
For k As Integer = 0 To dt.Rows.Count() - 1
dr(k) = dt.Rows(k)(j)
Next
dtNew.Rows.Add(dr)
Next
Return dtNew
End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

A WordPress.com Website.

Up ↑

%d bloggers like this: