• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Copying a selected list of columns from one datatable to another datatable

Hi Experts,
I have a datatable say dt1 with 30 columns with some data. I wanted to create another data table say dt2 with a subset of columns from dt1, along with the data.

Kindly help me.

Thanks & Regards,

  • 2
1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
for what doing with it?
if you want to "filter out" certain columns for a data grid, well simply hide the columns in the datagrid you don't want to see...
kishoreb123Author Commented:
taking a scenario of thirty columns or more, it would be easier to copy only those two or three required columns into new table instead of looping and hiding the remaining 28 columns.

Filtering is filtering the rows, i wanted to restrict the columns being copied..


you can try creating a datatable using totable method of dataview class as follows

Dim dv As DataView = New DataView(dt1)
' if you want distinct data use
dim dt2 as datatable = dv.totable(true, "col1","col2")
' if you want all data use
dim dt2 as datatable = dv.totable(false, "col1","col2")

for more info on totable method.
kishoreb123Author Commented:
Thanks !  Done.. Enoromous no.of methods..very difficult to identify which one helps.

Thanks again..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now