VB.Net - DataColumn

Issue: My export to excel function provides column names based on the column names from the database. Actually, I would prefer to customize those column names. This is done by defining a dataset, (or a datatable) and then overriding the ColumnName property from the Columns collection of that datatable.

Here is a sample

1
2
3
4
5
6
7
8
9
10
11
12
Dim ds As DataSet _
= Staff.SupvBackups.GetDs()

'
' rename columns to make them easier to read in the exported file
ds.Tables(0).Columns(0).ColumnName = "ID (Ignore)"
ds.Tables(0).Columns(1).ColumnName = "Backup Compass Id"
ds.Tables(0).Columns(2).ColumnName = "Backup Supervisor"
ds.Tables(0).Columns(3).ColumnName = "Compass Id"
ds.Tables(0).Columns(4).ColumnName = "Compass Supervisor"

SI.Excel.Export2Excel(ds, Response)

in the sample above you see backup columns first. But if you wanted to re-arrange the columns you would use the set ordinal method. Here is an example

1
2
3
4
5
ds.Tables(0).Columns("ID (Ignore)").SetOrdinal(0)
ds.Tables(0).Columns("Compass Id").SetOrdinal(1)
ds.Tables(0).Columns("Compass Supervisor").SetOrdinal(2)
ds.Tables(0).Columns("Backup Compass Id").SetOrdinal(3)
ds.Tables(0).Columns("Backup Supervisor").SetOrdinal(4)