Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now