Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用SQL和gridview在gridview中显示学生出勤情况_Sql_C# 4.0_Sql Server 2012 - Fatal编程技术网

如何使用SQL和gridview在gridview中显示学生出勤情况

如何使用SQL和gridview在gridview中显示学生出勤情况,sql,c#-4.0,sql-server-2012,Sql,C# 4.0,Sql Server 2012,我正在使用SQL Server 2012和VS 2012 C# 我已经设计了数据库表Roll\u No,attendent\u Date,attendent\u Status 在存储数据时,我是这样存储的 ______________________________________ Roll_No Attend_Date Attend_Status --------------------------------------- 1 04-01-14 1 2 04-01-14

我正在使用SQL Server 2012和VS 2012 C# 我已经设计了数据库表Roll\u No,attendent\u Date,attendent\u Status 在存储数据时,我是这样存储的

______________________________________
Roll_No Attend_Date Attend_Status
---------------------------------------
1   04-01-14    1
2   04-01-14    1
3   04-01-14    1
1   05-01-14    0
2   05-01-14    1
3   05-01-14    0
1   06-01-14    1
2   06-01-14    1
3   06-01-14    1
----------------------------------------
__________________________________________________________________
Roll_No 04-01-14    05-01-14    06-01-14    07-01-14
-------------------------------------------------------------------
1   1              0              1             1
2   1              1              1             1
3   1              0              1             1
-------------------------------------------------------------------
但我必须在网格视图中这样显示

______________________________________
Roll_No Attend_Date Attend_Status
---------------------------------------
1   04-01-14    1
2   04-01-14    1
3   04-01-14    1
1   05-01-14    0
2   05-01-14    1
3   05-01-14    0
1   06-01-14    1
2   06-01-14    1
3   06-01-14    1
----------------------------------------
__________________________________________________________________
Roll_No 04-01-14    05-01-14    06-01-14    07-01-14
-------------------------------------------------------------------
1   1              0              1             1
2   1              1              1             1
3   1              0              1             1
-------------------------------------------------------------------
你能帮我吗。。。
如何实现此结果。

您可以在执行透视时将每个日期列为列名,或者使用动态SQL生成列列表,然后应用透视

输出

Rollno  04-01-14  05-01-14  06-01-14
1             1      1       1
2             1      0       1
3             0      1       0

现在,您可以将此结果集绑定到GridView

为什么不使用DataTable试试呢。构建具有所需输出的datatable,并将该datatable绑定到datagridview。dataGridView1.datasource=DataTableThank@mhasan,我得到了我想要的结果。。工作正常。。我去年用过PIVOT。。但这比你想象的要复杂得多。@user2875907。。干杯。。新年快乐