当前位置:网站首页>ASPX DataTable 行列互换
ASPX DataTable 行列互换
2022-06-09 19:36:00 【白露-】
一.DataTable 行列互换
//设置表格的数据源为查询的数据表
clsDBAccess DBAC1 = new clsDBAccess();
DataTable table = DBAC1.QueryTable(sql, "test", "test");//封装的sql语句,返回DataTable类型
//自己创建一个新的DataTable
DataTable table2 = new DataTable();
//添加第一行的第一列,这里的名字定义为姓名,可以为空
table2.Columns.Add("姓名", typeof(string));
//创建第二行
DataRow dr = table2.NewRow();
//第二行的第一列为班级
dr[0] = "班级";
//创建第三行
DataRow dr2 = table2.NewRow();
//第三行的第一列为是否合格
dr2[0] = "是否合格";
//将数据库的数据遍历
for (int i = 0; i < table.Rows.Count; i++)
{
//姓名列(name为你原表的行)
String nameindex=table.Rows[i]["name"].ToString();
//遍历姓名列
table2.Columns.Add(nameindex, typeof(string));
//用姓名列对应其班级(classes为你原表的行)
dr[nameindex] = table.Rows[i]["classes"].ToString();
//用姓名列对应其是否合格(qualified为你原表的行)
dr2[nameindex] = table.Rows[i]["qualified"].ToString();
}
//将两行添加
table2.Rows.Add(dr);
table2.Rows.Add(dr2);
dateView.DataSource = table2;
//绑定事件
dateView.DataBind();
2.计算某列和
for (int i = 0; i < table.Rows.Count; i++)
{
tot += Convert.ToInt32(table.Rows[i]["number"].ToString());
}
table.Clear();
边栏推荐
- The number of developers soared by 1.8 million in 24 months, and rust ushered in a highlight moment
- <collection>和<association>标签
- Another college entrance examination season, 12 years have passed in the twinkling of an eye
- Redis生成全局唯一ID的实现方法
- Pourquoi Google Search ne peut - il pas Pager indéfiniment?
- 企业内部Wiki,你建立了么?
- 散列表 分布式散列表(DHT)哈希表
- CL210OpenStack操作的故障排除--诊断OpenStack问题
- Visual display of cool 3D charts
- C语言实现猜数字游戏
猜你喜欢

2022 "network security" competition of secondary vocational group freshmen test of Shandong Zibo Industrial school competition assignment

24个月暴涨180万名开发者,Rust 迎来高光时刻

二叉树的按层遍历
MySQL has no service and the ultimate solution sharing that the service cannot be started

C语言实现电脑自动关机程序--可以用来恶搞舍友电脑
![[ue5] calling worldsubsystem in uobject](/img/0d/ccc5b3b481eb8015f5a2bedb0d22d0.png)
[ue5] calling worldsubsystem in uobject

泛微OA9前台无限制getshell

版号批下来,可公司已倒闭:现如今,做款游戏还能卖给腾讯吗?

【UE5】UObject中调用WorldSubsystem

《微信小程序-基础篇》初识微信小程序
随机推荐
整形有序数组查找--遍历法与折半法/二分法
Download and install node using NVM
Intel, Samsung, Qualcomm, etc. will form a group to acquire arm?
Mobile application testing (6) - App Testing Technology (4)
面试字节测开岗失败后,被面试官在朋友圈吐槽了......(心累)
企业内部Wiki,你建立了么?
uniapp h5单页面横屏
The company is suspected of violating the ban to provide technical support to Huawei Hisilicon. Xinsi technology said it was cooperating with the U.S. government in the investigation
C语言实现猜数字游戏
10个常见触发IO瓶颈的高频业务场景
TKE搭建EFK日志服务
Assignment for "information security management and evaluation" of higher vocational group in 20XX national vocational college skills competition
普通三进制逻辑数学世界先驱者——伍耀晖先生面向全球公布普通三进制逻辑数学全部真值表科研成果(伍氏定律)
写代码的小技巧
Exploration and analysis of hidden information of network security system vulnerabilities in Secondary Vocational Schools
MySQL 8.0.27 installation and configuration tutorial under Windows
Investment of 550million yuan! Merck announced to build an advanced semiconductor integration base in Zhangjiagang, China
<collection>和<association>标签
VNCTF 2022 InterestingPHP
高校社团管理系统