MS-Access / Getting Started

Building the Application

Follow these steps to write in the BuildApplication method to meet the requirements:

  1. Create the target database. (This is the end result of the build.)
  2. Set build properties on the target database.
  3. Set build properties on the source database.
  4. Delete data from tables in the target database.

Using programming by intention, write the BuildApplication method as follows. We'll fill in the dependent methods along the way. Start with the declaration and a call to the method.

CreateTargetDatabase. We're wrapping the code in a try/catch block to handle any exceptions that are thrown:

private void BuildApplication()
	// get the target database
	targetDatabase = CreateTargetDatabase();

Next, we need to set properties on both the target and source databases. To do that, add the following code. These methods will be implemented in a few moments.

// set properties on the target and source databases

The next thing we need to do is delete the data from the selected tables. Add the following code to call a method that will do that:

// delete data from tables

Next, close the source database and finish the try block:

// close the source database
// success!
MessageBox.Show("Application built successfully!",
    "Build Complete",
    MessageBoxButtons.OK, MessageBoxIcon.Information);

Two different exceptions may be thrown: a COMException if one of the user-defined properties is null, and NullReferenceException if the target database was not created. Handle both of these exceptions with the following catch blocks. We've added a finally block to make sure that the target database is closed:

catch (COMException ex)
    if (ERR_PROP_ISNULL == ex.ErrorCode)
	errorText = "Custom database property cannot be null";
catch (NullReferenceException)
    // close target database in the finally block to ensure closure
[Previous] [Contents] [Next]