Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a datatable like this:

column1 | column2 | column3 | column4   | column5
-------------------------------------------------
TypeABC | Jan     | 2012    | location1 | 14
TypeABC | Jan     | 2012    | location2 | 19
TypeABC | Feb     | 2012    | location1 | 17
TypeABC | Feb     | 2012    | location2 | 55


I want a datatable like this one using linq:

Column1 | Column2 | Column3 | Column4(location1) | Column5(location2)
---------------------------------------------------------------------
TypeABC | Jan     | 2012    | 14                 | 19
TypeABC | Feb     | 2012    | 17                 | 55


Any suggestion is appreciated.

Thank you.
Posted
Updated 24-Feb-13 10:55am
v2
Comments
Ankur\m/ 18-Feb-13 0:01am    
So what have you tried?
[no name] 18-Feb-13 4:24am    
I tried to split into two tables and combine into one again with join, but I want it be done without all this long process, So I am looking for linq query, I know what to do, but I am poor at linq syntax..... so seeking help

1 solution

My suggestion would be to look into the Enumerable.GroupBy[^] extension method. You can then use Enumerable.Select[^] and Enumerable.SelectMany[^] to manipulate the results into the form you want.

As an aside: spending a little time to make your question clearer and easier to read can make people more willing to answer your questions. For layouts like the one you've used to represent your tables, <pre> tags are your friend, as they are shown using a fixed-width font.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900