Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSW_8_11.doc
Скачиваний:
2
Добавлен:
01.05.2025
Размер:
5 Мб
Скачать
☆

Registering the Database

Before you can create a database application, you must have the database that you want to access registered with the system. This process registers the selected tables in the database as data sources that you can access through the ODBC driver. Follow the steps that come next to accomplish this important task.

1. Create a folder called Database on your hard disk. Contain file DeptStore.mdb created with Microsoft Access to that folder. You use this database as the data source for the Employee application.

2. From the Windows 95 Start menu, run Control Panel. When Control Panel appears, double-click the 32-Bit ODBC icon. The ODBC Data Source Administrator property sheet appears.

3. Select the User DSN tab, and then click the Add button. The Create a New Data Source wizard appears. Select the Microsoft Access Driver from the list of drivers, and click the Finish button.

The Microsoft Access Driver is now the ODBC driver that will be associated with the data source that you'll create for the Employee application.

4. When the ODBC Microsoft Access 97 Setup dialog box appears, enter Department Store into the Data Source Name text box and then enter Department Store Database in the Description text box.

The data source name is simply a way of identifying the specific data source that you're creating. The description field enables you to include more specific information about the data source.

5. Click the Select button. The Select Database file selector appears. Use the selector to locate and select the DeptStore.mdb file.

6. Click OK to finalize the database selection, and then, in the ODBC Microsoft Access 7.0 Setup dialog box, click OK to finalize the data source creation process. Finally, click OK in the ODBC Data Source Administrator property sheet to dismiss the property sheet.

Your system is now set up to access the DeptStore.mdb database file with the Microsoft Access ODBC driver.

Creating the Basic Employee Application

Now that you have your data source created and registered, it's time to create the basic Employee application. The steps that follow lead you through this process. After you've completed these steps, you'll have an application that can access and view the Employees table of the Department Store database.

1. Choose File, New from Developer Studio's menu bar. The New property sheet appears.

2. Make sure that MFC AppWizard (exe) is selected in the left hand pane. Then type Employee into the Project Name box, and click the Create button. The Step 1 dialog box appears.

4. Choose Single Document, and then click the Next button. The Step 2 dialog box appears.

Choosing the Single Document option ensures that the Employee application will not allow more than one window to be open at a time.

5. Choose the Database View Without File Support option button, and then click the Data Source button. The Database Options dialog box appears.

By Choosing the Database View Without File Support option, you're telling AppWizard to automatically generate the classes you need to view the contents of a database. This application will not use any supplemental files besides the database, so it doesn't need file (serializing) support.

6. In the ODBC drop-down list, Choose the Department Store data source. Click the OK button, and the Select Database Tables dialog box appears, as shown in Figure 22.12.

7. Choose the Employees table, and then click OK. The Step 2 dialog box reappears, filled in as shown in Figure 22.13.

You've now associated the Employees table of the Department Store data source with the Employee application.

8. Click the Next button two times. The Step 4 dialog box appears.

9. Turn off the Printing and Print Preview option, and then click the Finish button to finalize your selections for the Employee application.

10. Click the OK button, and AppWizard creates the basic Employee application.

You've now created the basic Employee application. At this point, you can compile the application by clicking the Build button on Developer Studio's toolbar, by choosing the Build, Build command from the menu bar, or by pressing F7 on your keyboard. After the program has compiled, choose the Build, Execute command from the menu bar or press Ctrl+F5 to run the program. You can use the database controls in the application's toolbar to navigate from one record in the Employees table to another. However, nothing appears in the window because you've yet to associate controls with the fields in the table that you want to view. You do that in the following section.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]