Convert Data table to Pivot data table c#
up vote
0
down vote
favorite
I have data table in c# project as follows,
I want to pivot/convert this data table in following format,
[Expected format]
Where Section will become distinct rows.
Keys will become Columns and values will get added into appropriate keys.
c# asp.net c#-4.0 c#-3.0 ini
add a comment |
up vote
0
down vote
favorite
I have data table in c# project as follows,
I want to pivot/convert this data table in following format,
[Expected format]
Where Section will become distinct rows.
Keys will become Columns and values will get added into appropriate keys.
c# asp.net c#-4.0 c#-3.0 ini
I think this entry: techbrij.com/pivot-c-array-datatable-convert-column-to-row-linq can help you with your request. It's a general approach for convertingDataTable
s orArray
s to "pivot".
– RedFox
Nov 9 at 9:18
@RedFox it has last item as number/int, in my case it is string only. var pivotTable = data.ToPivotTable( item => item.Year, item => item.Product, items => items.Any() ? items.Sum(x=>x.Sales) : 0);
– pankaj bawdane
Nov 9 at 9:26
If you want non distinct values for the column names (e.g. Customer) you can not use a DataTable, because it would throw anDuplicateNameException
. If you need the "same" column multiple times then you could number them consecutively. If you need distinct columns you have to define the value that should be selected in thedataSelector
.
– RedFox
Nov 9 at 9:55
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have data table in c# project as follows,
I want to pivot/convert this data table in following format,
[Expected format]
Where Section will become distinct rows.
Keys will become Columns and values will get added into appropriate keys.
c# asp.net c#-4.0 c#-3.0 ini
I have data table in c# project as follows,
I want to pivot/convert this data table in following format,
[Expected format]
Where Section will become distinct rows.
Keys will become Columns and values will get added into appropriate keys.
c# asp.net c#-4.0 c#-3.0 ini
c# asp.net c#-4.0 c#-3.0 ini
asked Nov 9 at 9:07
pankaj bawdane
398
398
I think this entry: techbrij.com/pivot-c-array-datatable-convert-column-to-row-linq can help you with your request. It's a general approach for convertingDataTable
s orArray
s to "pivot".
– RedFox
Nov 9 at 9:18
@RedFox it has last item as number/int, in my case it is string only. var pivotTable = data.ToPivotTable( item => item.Year, item => item.Product, items => items.Any() ? items.Sum(x=>x.Sales) : 0);
– pankaj bawdane
Nov 9 at 9:26
If you want non distinct values for the column names (e.g. Customer) you can not use a DataTable, because it would throw anDuplicateNameException
. If you need the "same" column multiple times then you could number them consecutively. If you need distinct columns you have to define the value that should be selected in thedataSelector
.
– RedFox
Nov 9 at 9:55
add a comment |
I think this entry: techbrij.com/pivot-c-array-datatable-convert-column-to-row-linq can help you with your request. It's a general approach for convertingDataTable
s orArray
s to "pivot".
– RedFox
Nov 9 at 9:18
@RedFox it has last item as number/int, in my case it is string only. var pivotTable = data.ToPivotTable( item => item.Year, item => item.Product, items => items.Any() ? items.Sum(x=>x.Sales) : 0);
– pankaj bawdane
Nov 9 at 9:26
If you want non distinct values for the column names (e.g. Customer) you can not use a DataTable, because it would throw anDuplicateNameException
. If you need the "same" column multiple times then you could number them consecutively. If you need distinct columns you have to define the value that should be selected in thedataSelector
.
– RedFox
Nov 9 at 9:55
I think this entry: techbrij.com/pivot-c-array-datatable-convert-column-to-row-linq can help you with your request. It's a general approach for converting
DataTable
s or Array
s to "pivot".– RedFox
Nov 9 at 9:18
I think this entry: techbrij.com/pivot-c-array-datatable-convert-column-to-row-linq can help you with your request. It's a general approach for converting
DataTable
s or Array
s to "pivot".– RedFox
Nov 9 at 9:18
@RedFox it has last item as number/int, in my case it is string only. var pivotTable = data.ToPivotTable( item => item.Year, item => item.Product, items => items.Any() ? items.Sum(x=>x.Sales) : 0);
– pankaj bawdane
Nov 9 at 9:26
@RedFox it has last item as number/int, in my case it is string only. var pivotTable = data.ToPivotTable( item => item.Year, item => item.Product, items => items.Any() ? items.Sum(x=>x.Sales) : 0);
– pankaj bawdane
Nov 9 at 9:26
If you want non distinct values for the column names (e.g. Customer) you can not use a DataTable, because it would throw an
DuplicateNameException
. If you need the "same" column multiple times then you could number them consecutively. If you need distinct columns you have to define the value that should be selected in the dataSelector
.– RedFox
Nov 9 at 9:55
If you want non distinct values for the column names (e.g. Customer) you can not use a DataTable, because it would throw an
DuplicateNameException
. If you need the "same" column multiple times then you could number them consecutively. If you need distinct columns you have to define the value that should be selected in the dataSelector
.– RedFox
Nov 9 at 9:55
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222697%2fconvert-data-table-to-pivot-data-table-c-sharp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think this entry: techbrij.com/pivot-c-array-datatable-convert-column-to-row-linq can help you with your request. It's a general approach for converting
DataTable
s orArray
s to "pivot".– RedFox
Nov 9 at 9:18
@RedFox it has last item as number/int, in my case it is string only. var pivotTable = data.ToPivotTable( item => item.Year, item => item.Product, items => items.Any() ? items.Sum(x=>x.Sales) : 0);
– pankaj bawdane
Nov 9 at 9:26
If you want non distinct values for the column names (e.g. Customer) you can not use a DataTable, because it would throw an
DuplicateNameException
. If you need the "same" column multiple times then you could number them consecutively. If you need distinct columns you have to define the value that should be selected in thedataSelector
.– RedFox
Nov 9 at 9:55