Datatable to a new DataTable

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I am trying to create a new file from a datatable (not sql server table).
I am doing it in this way at the moment:

Dim dataTable2 As DataTable = dataTable.Clone
drs = dataTable.Select("", "SortField,F5,F6")
For Each dr In drs
stemp = dr(1)
dr(1) = stemp.Substring(0, 2) & "/" & stemp.Substring(2, 2) & "/" &
stemp.Substring(4, 2)
dataTable2.ImportRow(dr)
Next

This works fine. But I need to be able to reorder the columns and drop
some. The problem with the above method is that it will create the new
datatable fine but will leave the columns the same.

It thought about using a DataView, but the problem is that when you use rows
they are DataRowViews not DataRows which is what ImportRow needs.

Is there a way to easily copy the DataTable to a new DataTable with a new
sort as I do above as well as new columns?

Thanks,

Tom
 
Back
Top