Link to home
Start Free TrialLog in
Avatar of the_bachelor
the_bachelor

asked on

Dataset Datable or Dataview Subset Exclude columns

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.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Use the DataTable.Copy method to get a copy, and then remove the columns that you don't need.

Bob
Avatar of the_bachelor
the_bachelor

ASKER

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)
Are you talking about from the database side, or from in-memory DataTable/DataSet?

Bob
in/memory Dataset/DataTable/Dataview side
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I havent found anything helpful. I guess I'm gunna have to agree with you there LeanedOne.
Maybe I should write my own.
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.