<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
string connectionString;
string queryString;
DataSet data = new DataSet();
OleDbConnection dbConnection;
OleDbDataAdapter dataAdapter;
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=C:\\BegASPNet11\\data\\Northwind.mdb";
queryString = "SELECT FirstName, LastName FROM Employees";
dbConnection = new OleDbConnection(connectionString);
dataAdapter = new OleDbDataAdapter(queryString, dbConnection);
dataAdapter.Fill(data, "Employees");
DataGrid1.DataSource = data;
DataGrid1.DataBind();
// ---------------------------------------------------------
DataTable table;
DataRow newRow;
table = data.Tables["Employees"];
newRow = table.NewRow();
newRow["FirstName"] = "Norman";
newRow["LastName"] = "Blake";
table.Rows.Add(newRow);
// bind the second grid to the new data
DataGrid2.DataSource = table;
// ---------------------------------------------------------
DataRow[] selectedRows;
// find the row to change
selectedRows = table.Select("FirstName='Margaret' AND
LastName='Peacock'");
selectedRows[0]["FirstName"] = "John";
selectedRows[0]["LastName"] = "Hartford";
// bind the third grid to this new data
DataGrid3.DataSource = table;
DataGrid3.DataBind();
// ---------------------------------------------------------
// The Rows collection is 0 indexed, therefore
// this deletes the sixth row
table.Rows[5].Delete();
// bind the fourth grid to the new data
DataGrid4.DataSource = table;
DataGrid4.DataBind();
}
</script>