using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//数据库连接,记录集的获取
//注意更改路径
String sqlconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = E:/pro/web/access_test/app_data/Northwind.mdb;Jet OLEDB:Database Password=111111";
OleDbConnection myConnection = new OleDbConnection(sqlconn);
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("select * from 运货商", myConnection);
OleDbDataReader myReader;
myReader = myCommand.ExecuteReader();
//读取记录集
Response.Write("table border=1 cellspacing=0 cellpadding=2>");
Response.Write("tr bgcolor=#DAB4B4>");
for (int i = 0; i myReader.FieldCount; i++)
Response.Write("td>" + myReader.GetName(i) + "/td>");
Response.Write("/tr>");
while (myReader.Read())
{
Response.Write("tr>");
for (int i = 0; i myReader.FieldCount; i++)
Response.Write("td>" + myReader[i].ToString ()+ "/td>");
Response.Write("/tr>");
}
Response.Write("/table>");
//关闭记录集和连接
myReader.Close();
myConnection.Close();
}
}