zoukankan
html css js c++ java
DataTable应用
code
using
System;
using
System.Collections;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
public
partial
class
DataTable应用 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
btnCreate_Click(
object
sender, System.EventArgs e)
{
DataSet dsUntyped
=
new
DataSet(
"
myDS
"
);
//
创建数据集
DataTable dtMaster
=
new
DataTable(
"
Master
"
);
//
创建数据表
DataTable dtChild
=
new
DataTable(
"
Child
"
);
dsUntyped.Tables.Add(dtMaster);
//
把数据表添加到数据集中
dsUntyped.Tables.Add(dtChild);
Session[
"
ds
"
]
=
dsUntyped;
}
protected
void
btnAddColumn_Click(
object
sender, System.EventArgs e)
{
DataSet dsUntyped
=
(DataSet)Session[
"
ds
"
];
dsUntyped.Tables[
"
Master
"
].Columns.Add(
"
MasterID
"
,
typeof
(
int
));
dsUntyped.Tables[
"
Master
"
].Columns.Add(
"
MasterValue
"
,
typeof
(
string
));
dsUntyped.Tables[
"
Child
"
].Columns.Add(
"
MasterLink
"
,
typeof
(
int
));
dsUntyped.Tables[
"
Child
"
].Columns.Add(
"
ChildID
"
,
typeof
(
int
));
dsUntyped.Tables[
"
Child
"
].Columns.Add(
"
ChildValue
"
,
typeof
(
string
));
//
修改表头
dsUntyped.Tables[
"
Master
"
].Columns[
"
MasterID
"
].Caption
=
"
主ID
"
;
dsUntyped.Tables[
"
Master
"
].Columns[
"
MasterValue
"
].Caption
=
"
值
"
;
Session[
"
ds
"
]
=
dsUntyped;
Bind();
}
protected
void
btnAddRow_Click(
object
sender, System.EventArgs e)
{
try
{
DataSet dsUntyped
=
(DataSet)Session[
"
ds
"
];
//
为Master表添加两行
DataRow dr
=
dsUntyped.Tables[
"
Master
"
].NewRow();
dr[
"
MasterID
"
]
=
1
;
dr[
"
MasterValue
"
]
=
"
One
"
;
dsUntyped.Tables[
"
Master
"
].Rows.Add(dr);
dr
=
dsUntyped.Tables[
"
Master
"
].NewRow();
dr[
"
MasterID
"
]
=
2
;
dr[
"
MasterValue
"
]
=
"
Two
"
;
dsUntyped.Tables[
"
Master
"
].Rows.Add(dr);
//
为child表添加1行
dr
=
dsUntyped.Tables[
"
Child
"
].NewRow();
dr[
"
MasterLink
"
]
=
1
;
dr[
"
ChildID
"
]
=
1
;
dr[
"
ChildValue
"
]
=
"
ChildOne
"
;
dsUntyped.Tables[
"
Child
"
].Rows.Add(dr);
Session[
"
ds
"
]
=
dsUntyped;
Bind();
}
catch
(Exception ee)
{
Response.Write(ee.Message);
}
}
//
添加唯一键
protected
void
Button1_Click(
object
sender, System.EventArgs e)
{
DataSet dsUntyped
=
(DataSet)Session[
"
ds
"
];
//
表示对一组列的限制,列中所有值必须是唯一的
System.Data.UniqueConstraint uc
=
new
UniqueConstraint(
"
unqi
"
, dsUntyped.Tables[
"
Master
"
].Columns[
"
MasterID
"
]);
dsUntyped.Tables[
"
Master
"
].Constraints.Add(uc);
Session[
"
ds
"
]
=
dsUntyped;
}
private
void
Bind()
{
DataSet dsUntyped
=
(DataSet)Session[
"
ds
"
];
dgMaster.DataSource
=
dsUntyped.Tables[
"
Master
"
].DefaultView;
dgChild.DataSource
=
dsUntyped.Tables[
"
Child
"
].DefaultView;
this
.DataBind();
}
protected
void
btnAddForeign_Click(
object
sender, System.EventArgs e)
{
//
添加外键
DataSet dsUntyped
=
(DataSet)Session[
"
ds
"
];
System.Data.ForeignKeyConstraint fc
=
new
ForeignKeyConstraint(
"
fc
"
, dsUntyped.Tables[
"
Master
"
].Columns[
"
MasterID
"
], dsUntyped.Tables[
"
Child
"
].Columns[
"
MasterLink
"
]);
dsUntyped.Tables[
"
Child
"
].Constraints.Add(fc);
Session[
"
ds
"
]
=
dsUntyped;
}
protected
void
btnUpdateMID_Click(
object
sender, System.EventArgs e)
{
DataSet dsUntyped
=
(DataSet)Session[
"
ds
"
];
dsUntyped.Tables[
"
Master
"
].Rows[
0
][
"
MasterID
"
]
=
4
;
Bind();
}
protected
void
Button2_Click(
object
sender, System.EventArgs e)
{
DataSet dsUntyped
=
(DataSet)Session[
"
ds
"
];
int
nIndexTb
=
int
.Parse(ddlTable.SelectedItem.Value);
int
nIndexRow
=
int
.Parse(tbRow.Text);
int
nIndexCol
=
int
.Parse(tbCol.Text);
object
obj
=
dsUntyped.Tables[nIndexTb].Rows[nIndexRow][nIndexCol];
tbResult.Text
=
obj.ToString();
}
protected
void
btnUpdateDs_Click(
object
sender, System.EventArgs e)
{
DataSet dsUntyped
=
(DataSet)Session[
"
ds
"
];
int
nIndexTb
=
int
.Parse(ddlTable.SelectedItem.Value);
int
nIndexRow
=
int
.Parse(tbRow.Text);
int
nIndexCol
=
int
.Parse(tbCol.Text);
dsUntyped.Tables[nIndexTb].Rows[nIndexRow][nIndexCol]
=
tbResult.Text;
Session[
"
ds
"
]
=
dsUntyped;
Bind();
}
}
查看全文
相关阅读:
NumPy 百题大冲关,冲鸭!
33 个送给 Java 程序员的练手项目合集
比特币——带你掌握未来的技术和财富
HTML5 蔡徐坤打篮球游戏 NMSL❤️❤️❤️
网络协议基础:“工作中模模糊糊的概念,这次终于理顺了!”
昨天521表白失败,我想用Python分析一下...表白记录和聊天记录
有哪些好用不火的软件?
如何处理负载、高并发?
怎么实现第三方登录?
购物车的原理?
原文地址:https://www.cnblogs.com/hubcarl/p/1423536.html
最新文章
PHP执行系统命令
ImageMagick又一处命令执行
老外一些比较火爆的论坛
日志清理批处理
cmd 一键获取 所有连接过的wifi 密码
通过一张图片定位真实地址
wget 下载整个网站,或者特定目录
安卓APP测试之使用Burp Suite实现HTTPS抓包方法
sqlmap 1.0.21 tamper 总结
Linux下getopt()函数的简单使用
热门文章
Java Zip压缩实现
斐波那契序列
Java异常处理中finally中的return会覆盖catch语句中的return语句
Java匿名内部类
java中导入常量
Java利用Math.random()方法随机生成A-Z的字符
Java字面常量与常量池
Java中String对象的不可变性
word2013中取消句首字母自动大写
18个堪称神器的命令行工具,高效运维必备
Copyright © 2011-2022 走看看