前端

img bgu

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

发表于2004/9/21 19:54:00  623人阅读

分类: [My ASP/ASP.net(C#)]

<%@ 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
   while (dr.Read())
   {
    Response.Write("<table><tr><td>" + dr["name"].ToString() + "</td><td>" + dr["password"].ToString() + "</td></tr>");
   }
   Response.Write("</table>");
 }

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

阅读全文
0 0

相关文章推荐

img
取 消
img