Click here to Skip to main content
Rate this: bad
good
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
 

Thanks
Shafi
Posted 13-Mar-13 23:25pm

1 solution

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

Solution 1

Read about SQL PIVOT:
MSDN: Using PIVOT and UNPIVOT[^]
Understanding PIVOT and UNPIVOT[^]
Pivoting data in SQL Server[^]
 
Try out! Post specific issue if you face any.
  Permalink  
Comments
shafi_sunshine at 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
 
Thanks
shafi
Sandeep Mewara at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 14 Mar 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