Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

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.
 
Share this answer
 
Comments
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

Thanks
shafi
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900