protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
string dbPath = @"Data/dbTest.mdb";
string db = Server.MapPath (dbPath);
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db;
string strSQL = "SELECT [CustomerID],[Address] FROM Customers";
DataSet ds = new DataSet();
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbDataAdapter da = new OleDbDataAdapter(strSQL,conn);
//通过Connection链接数据库操作
da.Fill(ds,"testMdb");
DataGrid1.DataSource = ds.Tables["testMdb"].DefaultView;
DataGrid1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
string dbPath = @"Data/dbTest.mdb";
string db = Server.MapPath (dbPath);
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db;
string strSQL = "SELECT [CustomerID],[Address] FROM Customers";
DataSet ds = new DataSet();
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbDataAdapter da = new OleDbDataAdapter(strSQL,conn);
//通过Connection链接数据库操作
da.Fill(ds,"testMdb");
DataGrid1.DataSource = ds.Tables["testMdb"].DefaultView;
DataGrid1.DataBind();
}