Click here to Skip to main content
12,749,046 members (38,446 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
Hi Experts

I have Data in DataTable with 3 fields firstname,lastname,emailid

firstname lastname emailid
abc abc1 ---
xyz xyz1 ---
lmn lmn1 ---

Now i want to retrieve the data from datatable in pivot format and attach to grid like this

firstname abc xyz lmn
lastname abc1 xyz1 lmn1
emailid --- --- ---

how to acheive this

Any Help Would Be Greatly Appreciated

Posted 14-Mar-13 0:25am

1 solution

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

Solution 1

Read about SQL PIVOT:
Understanding PIVOT and UNPIVOT[^]
Pivoting data in SQL Server[^]

Try out! Post specific issue if you face any.
shafi_sunshine 14-Mar-13 7:13am
Thanks for ur reply,

I want the data in pivot format from dataset(datatable) not from sql

Can you suggest me any solution for this

Sandeep Mewara 14-Mar-13 7:17am
When such operation is there, it's suggestible to do at DB level when you already have commands to do it.

At SQL level, PIVOT can be used. If for some reason you don't want it, then you need to create two for loops for two datatables and then copy column data of first table into rows of second. Do it for all. Just like you read column to row, you need to move the data from column to row. Use the datatable with shifted data.

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 | Mobile
Web01 | 2.8.170215.1 | Last Updated 14 Mar 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