Solved

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

Posted on 2006-11-11
4
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

630 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