Click here to Skip to main content
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
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 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2014
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