Solved

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

Posted on 2006-11-11
4
262 Views
Last Modified: 2008-03-10
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,



0
Comment
Question by:kishoreb123
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17920654
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...
0
 
LVL 5

Author Comment

by:kishoreb123
ID: 17920680
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..


Thanks
0
 
LVL 39

Accepted Solution

by:
appari earned 125 total points
ID: 17920709

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.
http://msdn2.microsoft.com/en-us/library/wec2b2e6.aspx
0
 
LVL 5

Author Comment

by:kishoreb123
ID: 17920737
Thanks !  Done.. Enoromous no.of methods..very difficult to identify which one helps.

Thanks again..
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question