<%@ 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>
本文地址:http://com.8s8s.com/it/it8579.htm