Datatable to a new DataTable

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top