ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Asp.Net学习笔记:使用DataSet

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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

<script 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();
}
</script>
<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>




相关文章

相关软件