// Execute the command
OleDbDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
MyDataGrid.DataSource = result ;
MyDataGrid.DataBind();
}
void MyDataGrid_EditCommand(Object sender, DataGridCommandEventArgs e)
{
MyDataGrid.EditItemIndex = e.Item.ItemIndex;
BindData();
}
void MyDataGrid_Cancel(Object sender, DataGridCommandEventArgs e)
{
MyDataGrid.EditItemIndex = -1;
BindData();
}
void MyDataGrid_UpdateCommand(Object sender, DataGridCommandEventArgs e)
{
OleDbConnection myConnection = CreateConnection();
string sql = "Select EmployeeID, FirstName, LastName, Title from Employees";
CuteEditor.Editor txtFirstName;
CuteEditor.Editor txtLastName;
CuteEditor.Editor txtTitle;
txtFirstName = (CuteEditor.Editor)e.Item.FindControl("FirstName_Box");
txtLastName = (CuteEditor.Editor)e.Item.FindControl("LastName_Box");
txtTitle = (CuteEditor.Editor)e.Item.FindControl("Title_Box");
string strUpdateStmt;
strUpdateStmt =" UPDATE Employees SET FirstName
=@Fname, LastName
=@Lname, Title = @Title WHERE EmployeeID = @EmpID";
OleDbCommand myCommand = new OleDbCommand(strUpdateStmt, myConnection);
myCommand.Parameters.Add(new OleDbParameter("@Fname", txtFirstName.Text));
myCommand.Parameters.Add(new OleDbParameter("@Lname", txtLastName.Text));
myCommand.Parameters.Add(new OleDbParameter("@Title", txtTitle.Text));
myCommand.Parameters.Add(new OleDbParameter("@EmpID", e.Item.Cells[1].Text ));
myCommand.ExecuteNonQuery();
MyDataGrid.EditItemIndex = -1;
BindData();
}
OleDbConnection CreateConnection()
{
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Context.Server.MapPath("../uploads/Northwind.mdb") + ";";
myConnection.Open();
return myConnection;
}
</script>