How to Import columns from one datatable to another
-
I have a datatable with around 6000 rows and 8 columns. Out of these, I want to extract all the 6000 rows but only 3 or 4 columns. Looping trhough row is not possible. How can i extract only the columns along with the rows to a new datatable? Please help. Is it possible using LINQ? I am using .Net 3.5. Thanks,
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
-
I have a datatable with around 6000 rows and 8 columns. Out of these, I want to extract all the 6000 rows but only 3 or 4 columns. Looping trhough row is not possible. How can i extract only the columns along with the rows to a new datatable? Please help. Is it possible using LINQ? I am using .Net 3.5. Thanks,
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
OK, I'll bite, why do you need it in a new DataTable?
Rhys "I'd rather die on my feet than live on my knees"
-
I have a datatable with around 6000 rows and 8 columns. Out of these, I want to extract all the 6000 rows but only 3 or 4 columns. Looping trhough row is not possible. How can i extract only the columns along with the rows to a new datatable? Please help. Is it possible using LINQ? I am using .Net 3.5. Thanks,
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
meeram395 wrote:
Looping trhough row is not possible.
Here is one way[^] DataTable.ReadXmlSchema Method[^]
thatraja |Chennai|India|
Brainbench certifications
Down-votes are like kid's kisses don't reject it :-)
Do what you want quickly because the Doomsday on 2012 :-) -
OK, I'll bite, why do you need it in a new DataTable?
Rhys "I'd rather die on my feet than live on my knees"
Why because, the requirement is that, the column name should be the name from the database which user entered through UI (User friendly column Names). And one column will be mapped to multiple columns, means column A in datatable 1 will be named as 'TestColumn1' and 'TestColumn2' even though the column values are exactly same. Also, only require 3 or 4 columns out of 8 or 10. So I can keep the existing table intact and copy only the required columns to new datatable and change the name.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.