Click here to Skip to main content
13,195,379 members (65,606 online)
Rate this:
Please Sign up or sign in to 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 17-Feb-13 17:38pm
Updated 24-Feb-13 10:55am
Ankur\m/ 18-Feb-13 0:01am
So what have you tried?
shabarnadh.vempati 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
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171019.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2017
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