Click here to Skip to main content
11,408,708 members (63,636 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET LINQ C#4.0
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 17-Feb-13 18:38pm
PBGuy1.8K
Edited 24-Feb-13 11:55am
v2
Comments
Ankur\m/ at 18-Feb-13 0:01am
   
So what have you tried?
shabarnadh.vempati at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 284
2 Maciej Los 155
3 Peter Leow 140
4 PIEBALDconsult 130
0 Sergey Alexandrovich Kryukov 8,626
1 OriginalGriff 6,855
2 Maciej Los 3,322
3 Abhinav S 3,238
4 Peter Leow 3,034


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100