?
Solved

Dataset Datable or Dataview Subset Exclude columns

Posted on 2007-07-30
7
Medium Priority
?
1,242 Views
Last Modified: 2012-06-27
I have a datatable initiaDT with columns A, B, C, ... H.
I want to have a subset of such datable subsetDt with columns B, D, G
Is there a way to do that w/o looping through every row of initiaDT ?

Same thing applies for a Dataset or Dataview.
0
Comment
Question by:the_bachelor
  • 3
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19598940
Use the DataTable.Copy method to get a copy, and then remove the columns that you don't need.

Bob
0
 
LVL 7

Author Comment

by:the_bachelor
ID: 19600166
I thought about doing something similar but that didnt seem "elegant" to me.
I was hoping that I'd be able so run some sort of adhoc select on the data (set, table, or view)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19600671
Are you talking about from the database side, or from in-memory DataTable/DataSet?

Bob
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 7

Author Comment

by:the_bachelor
ID: 19656026
in/memory Dataset/DataTable/Dataview side
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 19656113
There isn't any mechanism for a DataTable to select only a specific set of columns, like an SQL query.  The DataTable.Select method returns an array of DataRow instances that match a filter criteria (Name = 'Bob'), but they have all the columns that the source DataTable does.

Bob
0
 
LVL 7

Author Comment

by:the_bachelor
ID: 19670032
I havent found anything helpful. I guess I'm gunna have to agree with you there LeanedOne.
Maybe I should write my own.
0
 

Expert Comment

by:kainhart
ID: 21865209
With the advent of LINQ you can write an expression which would limit down the returned columns within a project much like a SQL select command. When running a LINQ expression on a DataTable one of the options for getting at the results is to use the ToDataTable method which should return a DataTable with the projected columns from your expression. This methodology allows many of hte SQL like SET based commands to be done within C# in a way that is concise and probably more efficient than copying a DataTable and then removing columns.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

807 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