Click here to Skip to main content
11,647,828 members (63,060 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 17:38pm
PBGuy1.8K
Edited 24-Feb-13 10: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 jyo.net 500
1 F-ES Sitecore 410
2 DamithSL 290
3 CPallini 290
4 OriginalGriff 277
0 OriginalGriff 1,342
1 jyo.net 994
2 DamithSL 971
3 Sergey Alexandrovich Kryukov 873
4 CPallini 795


Advertise | Privacy | Mobile
Web04 | 2.8.150804.4 | 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