Data Access Objects (DAO) Tutorial
DAOEnrol: Database Application, Lesson 1
Tip If you prefer working from a printed tutorial, see in MSDN Library Help for details about printing a lesson, a set of topics, or a single topic.
The DaoEnrol tutorial shows you how to develop an MFC database application using the Data Access Objects (DAO) database classes. This tutorial uses similar procedures and creates nearly the same application as the Enroll tutorial.
In the DaoEnrol tutorial, you’ll learn how to:
- Use AppWizard and ClassWizard for DAO database support.
- Create and use CDaoRecordset objects to open tables and run queries.
- Create and use CDaoRecordView objects for form-based applications.
- Use database support within the framework’s document/view architecture.
- Add, update, and delete records.
- Manage multiple tables.
- Handle database exceptions.
This lesson contains:
- Instructions for setting up the Student Registration database for DAO.
- A brief overview of DAO.
- Step 1 of the DaoEnrol tutorial, which explains how to create a database application using AppWizard.
- Step 2 of the DaoEnrol tutorial, which explains how to add a second recordset and use it to fill a combo box control on the form. Step 2 of DaoEnrol leverages material in Lesson 3 of the Enroll tutorial, with slight variations to accomodate minor differences in DAO.
- Step 3 of the DaoEnrol tutorial, which explains how to add and delete records. Step 3 of DaoEnrol leverages material from Lesson 4 of the Enroll tutorial, with slight variations to accomodate minor differences in DAO.
There are some differences in the code generated for DaoEnrol and the code generated for Enroll. Consequently there are separate instructions for some topics of DaoEnrol that need to be substituted for topics in Lessons 3 and 4. These topics are included at the end of this lesson in DaoEnrol Step 2 and DaoEnrol Step 3.
Note The http://msdn.microsoft.com/en-us/library/ms386426(v=vs.60).aspx sample reflects the completed DaoEnrol tutorial, plus an undocumented fourth step. Separate source code is not provided for each of the DaoEnrol tutorial steps either under Samples \ MFC Samples in the online documentation or on the Visual C++ distribution CD.
Important This tutorial assumes you are familiar with Visual C++ and MFC. If you aren’t, try the Scribble tutorial before you begin this tutorial. The Scribble tutorial introduces important class library concepts and techniques and teaches you to use the wizards and the resource editors.
It is not necessary to complete Enroll, the ODBC database classes tutorial, before starting DaoEnrol.
DAO recordset, database, and record view class implementations are very similar to that of the ODBC database classes. This means that skills and knowledge you may already have as a result of using the ODBC database classes can apply to the DAO database classes. By completing both the Enroll and DaoEnrol tutorials, you have the opportunity to compare the code and study both implementations. You can also use DaoEnrol as a basis for an application that uses more of MFC’s DAO functionality.