<%@ Page Inherits="ParentPage" src="Default.aspx.cs" %>
File: Default.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
public class ParentPage : Page {
public Label lblMessage;
public DataGrid DataGrid1;
private OleDbConnection objConn;
void Page_Load(Object Sender, EventArgs e) {
objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("EmployeeDatabase.mdb"));
if (!Page.IsPostBack) {
FillDataGrid();
}
}
private void FillDataGrid() {
FillDataGrid(-1);
}
private void FillDataGrid(int EditIndex) {
OleDbCommand objCmd = new OleDbCommand("select * from employee", objConn);
OleDbDataReader objReader;
try {
objCmd.Connection.Open();
objReader = objCmd.ExecuteReader();
DataGrid1.DataSource = objReader;
DataGrid1.DataBind();
objReader.Close();
} catch (OleDbException ex) {
lblMessage.Text = "Error retrieving from the database.";
}
objCmd.Connection.Close();
}
}