[我的ASP.net学习历程]DataReader(1)

类别:Asp 点击:0 评论:0 推荐:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ import Namespace="System.Data.OleDb" %>
<script language="C#" runat="server">

 void Page_Load()
 {
   string DB_path = @"Data\db.mdb";  //数据库路径
   string DB = Server.MapPath(DB_path);
   string strSQL = "SELECT * FROM [admin]";
   string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB;
   OleDbConnection conn = new OleDbConnection(connString);  //建立OleDbConnection对象
   OleDbCommand cmd = new OleDbCommand(strSQL,conn);  //建立OleDbCommand对象
   OleDbDataReader dr;  //建立DataReader对象
   cmd.Connection.Open();  //打开链接
   dr = cmd.ExecuteReader();  //建立DataReader
   DataGrid1.DataSource = dr;
   DataGrid1.DataBind();
 }

</script>
<asp:datagrid ID="DataGrid1" runat="server"></asp:datagrid>

本文地址:http://com.8s8s.com/it/it8580.htm