Asp.Net学习笔记:使用DataSet

Asp.Net学习笔记:使用DataSet
来源:从互联网收集整理并转载 

<% @ Page Language="C#" Debug="True"%>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>

<s cript language="C#" runat="server">
public void Page_Load(Object src,EventArgs e)
{
 //各种String 的设置
 String MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath("blog.mdb");
 String StrSel1 = "select id,topic,username,addtime from  blog";
 String StrSel2 = "select USERid,UserName,UserEmail from [user]";
 String StrSel3 = "select * from [subject]";

 DataSet MyDataSet = new DataSet();
 OleDbConnection MyConnection = new OleDbConnection(MyConnString);
 //open DataAdapter
 OleDbDataAdapter MyAdapter1 = new OleDbDataAdapter(StrSel1,MyConnection);
 OleDbDataAdapter MyAdapter2 = new OleDbDataAdapter(StrSel2,MyConnection);
 OleDbDataAdapter MyAdapter3 = new OleDbDataAdapter(StrSel3,MyConnection);

 //将各表数据存入DataSet
 MyAdapter1.Fill(MyDataSet,"blog");
 MyAdapter2.Fill(MyDataSet,"user");
 MyAdapter3.Fill(MyDataSet,"subject");

 //交给DataGrid显示
 DataGrid1.DataSource = MyDataSet.Tables["blog"].DefaultView;
 DataGrid2.DataSource = MyDataSet.Tables["user"].DefaultView;
 DataGrid3.DataSource = MyDataSet.Tables["subject"].DefaultView;
 DataGrid1.DataBind();
 DataGrid2.DataBind();
 DataGrid3.DataBind();
}
</s cript>
<html>
<head><title>DataSet的使用</title></head>
<body>
<form runat="server">
<ASP:DataGrid id="DataGrid1" runat="server"
AllowPaging="True"
PageSize="5"
PagerStyle-Mode="NumericPages"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
Cellpadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
/>
<hr />
<ASP:DataGrid id="DataGrid2" runat="server"
AllowPaging="True"
PageSize="4"
PagerStyle-Mode="NumericPages"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
Cellpadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
/>
<hr />
<ASP:DataGrid id="DataGrid3" runat="server"
AllowPaging="True"
PageSize="5"
PagerStyle-Mode="NumericPages"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
Cellpadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
/>
</form><p />
</body>
</html>

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值