前端

img bgu

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

发表于2004/9/21 19:52:00  907人阅读

<%@ 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>

阅读全文
0 0

相关文章推荐

img
取 消
img