Link to home
Start Free TrialLog in
Avatar of Jess31
Jess31

asked on

Select coumns form Data table?

Using vb.net.
I have a data-table with many column. I want a copy of this table (all rows) but only 2 of the columns. How can I do this?
Avatar of HainKurt
HainKurt
Flag of Canada image

what about copy / remove unwanted

dim copyDataTable as DataTable
copyDataTable = myTable.Copy()

copyDataTable.Columns.Remove("ColX")
copyDataTable.Columns.Remove("ColY")
...

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in vb.net ver:

Dim cols() As String = {"Col1", "Col2"}
        Dim dv As DataView = New DataView(dt)
        Dim newdt As DataTable = dv.ToTable(True, cols)

Open in new window