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();
}
}
查看全文
相关阅读:
java虚拟机小贴士之GC分析
hystrix文档翻译之工作原理
hystrix文档翻译之开始使用
SQLALchemy--ORM框架
PythonWEB框架之Flask--3
补充
PythonWEB框架之Flask--2
PythonWEB框架之Flask
centos6.8下redis的安装和配置
celery
原文地址:https://www.cnblogs.com/hubcarl/p/1423536.html
最新文章
PHP随机产生10个100以内互不相同的正整数按从小到大的顺序输出
MySQL字段值按照拼音首字母排序
php获取当前网页地址
tp5之允许跨域请求
Linux下putenv()函数导致composer更新失败
Redis常见的七种使用场景
Redis位操作介绍
deepin下挂载的的Windows系统(NTFC)目录怎么是只读的???
[学习笔记] 树上倍增求LCA
Code Forces 1030E
热门文章
Top Coder 某场Div 2的C题 题解
[学习笔记] 树状数组
[学习笔记] Treap
[学习笔记] Tarjan算法求强连通分量
hystrix文档翻译之metrics
hystrix文档翻译之配置
hystrix文档翻译之运维
jQuery简介
hystrix文档翻译之如何使用
java虚拟机之垃圾收集器
Copyright © 2011-2022 走看看