根据数据表字段自动生成新列 [英] Generate new columns automatically according to a datatable field
本文介绍了根据数据表字段自动生成新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下数据表
I have a datatable like below
name Subjects mark
---- -------- -----
Nim Chemistry 23
Nim Physics 24
Nim Maths 25
我想将此数据表绑定到如下所示的gridview
I want to bind this datatable to a gridview like below
Name Chemistry Physics Maths
------ --------- -------- -----
Nim 23 24 25
推荐答案
使用SQL Server PIVOT
SQL Server中的动态透视 [
Use SQL Server PIVOT
Dynamic Pivoting in SQL Server[^]
只需创建列为
的本地数据表 列1-名称
专栏2-化学
专栏3-物理
专栏4-数学
在这些数据表中添加行并说出gridview.datasource =数据表名称
Just create a local data table with columns as
Column1 - Name
Column2 - Chemistry
Column3 - Physics
Column4 - Maths
Add rows to these data table and say gridview.datasource = data table name
这篇关于根据数据表字段自动生成新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文