Solved

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

Posted on 2006-11-11
4
261 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 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 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