Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

let me explain some about database.

i have one table name called companydetails.

there are two fileds name called COmpanyID, DepartID.

COmpanyID , DEpartID.
1...................1.1
1...................1.2
1...................1.3
1...................1.4
2.......... ........2.1
2...................2.2
2.............. ....2.3
2 ..................2.4


This is my data appear in data base table.


Now my question is now i have to show this data in gridview in a 2 rows like this below.

COmpanyID,dept1,dept2,dept3,dept4

....1...........1.1.....1.2....1.3.....1.4
....2...........2.1.....2.1....2.3.....2.4




Please can you tell me how can i do this in c#.
Posted

1 solution

Hi,


you can do it by many logic. But give one logic.

Doing one thing. when you get table from database to your code. Loop on that table and again create new datatabel with your requirement.
 
Share this answer
 
Comments
Sandeep Mewara 4-Feb-11 4:33am    
Sure could be one but a bad one!

Would suggest to go directly via Query itself!
soni uma 4-Feb-11 4:37am    
Yes, But we have to give some logic idea how to doing. They can get whole code from net searching.

Ex.
http://technet.microsoft.com/en-us/library/ms177410.aspx show database logic.
Rajeshwar Code- Developer 4-Feb-11 4:37am    
Thnx Sandeep,

sandeep can you send me any ex code then i can work with that code..
Sandeep Mewara 4-Feb-11 4:39am    
Try looking for GroupBy CompanyId and then use PIVOT to change the orientation.

Useful link: http://technet.microsoft.com/en-us/library/ms177410.aspx
soni uma 4-Feb-11 4:41am    
oops! same same...

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