c# - how to get the sql horizontal database values vertically using asp.net -


i have table in sql server follows

studentid     subject    marks     1          telugu      70     1         english      80     1           maths       90     1           social      70 

i want display above table in gridview follows

 studentid   telugu   english   maths   social    total      1            70       80         90      70      310  

i tried using datatable using follows

i created datacolumns dynamically follows

while (dr.read())             {                dt.columns.add(dr["subname"].tostring(), typeof(string));             } 

but not getting idea insert marks dynamically shown above...

thanks in advance.... please me...

another way of doing using case

 select studentid         ,max(case when subject = 'telugu' marks end) telugu         ,max(case when subject = 'english' marks end) english         ,max(case when subject = 'maths' marks end) maths         ,max(case when subject = 'social' marks end) social         ,sum(marks) total  yourtable  group studentid 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -