Data Access Programming
Visual C++ provides several ways to work with databases. The preferred way is to use one of the class libraries such as the Active Template Class Library (ATL) or Microsoft Foundation Class (MFC) Library, which simplify working with the database APIs.
Note
This topic covers the legacy technologies you can use for database programming in Visual C++. For information on data access programming using Visual C++ and SQL Server 2005, see Data Access Using ADO.NET (C++/CLI), Accessing Data in Visual Studio, and Creating SQL Server Objects in Managed Code.
The library classes support the following kinds of data access:
ATL provides OLE DB templates and database attributes.
MFC provides Open Database Connectivity (ODBC) and an ODBC driver.
These libraries supply abstractions that simplify working with databases, complete with the speed, power, and flexibility of C++. They integrate your data access work with the library's application framework.
Alternately, you can directly call database API functions from the COM, ODBC, or DAO software development kits (SDKs). For information about programming directly with the COM, DAO, or ODBC API functions, see the COM SDK, DAO SDK, or ODBC SDK.
Use ATL OLE DB if you need to access data, regardless of the form in which it is stored. Use the MFC ODBC classes when you are not using Microsoft Jet (.mdb) databases and want to work with the ODBC API for complete data-source independence. Use the MFC DAO classes when you want to work with Microsoft Jet (.mdb) databases or with external databases such as ODBC data sources.
Note
Microsoft recommends using OLE DB or ODBC for new projects. DAO should only be used in maintaining existing applications.
Besides writing stand-alone database applications, you can often use a database effectively in other kinds of programs as a convenient storage and retrieval medium.
To learn more about |
See |
---|---|
Selecting a database technology |
|
ODBC vs. DAO |
|
Using the Microsoft Knowledge Base to find additional articles on database topics written by product support engineers |
|
ATL Database Support (OLE DB) |
|
OLE DB programming (conceptual topics) |
|
Using the OLE DB consumer templates (conceptual topics) |
|
OLE DB consumer attributes |
|
Using the OLE DB provider templates (conceptual topics) |
|
Adding an OLE DB consumer to an MFC project |
|
MFC Database Support (ODBC and DAO) |
|
What DAO and ODBC are |
|
When to use the MFC database classes |
|
Learn about the MFC database programming model |
|
Choose between the MFC DAO classes and the MFC ODBC classes |
|
Data sources you can access with DAO and ODBC |
|
Open Database Connectivity (ODBC) |
|
Whether you can call DAO or ODBC APIs directly while using the classes |
|
What ODBC drivers are provided |
|
How the database classes work with the MFC document/view architecture |
|
Installing MFC database support; what ODBC drivers are installed in Visual C++ by default; what ODBC and DAO SDK components are installed |
|
Data-Bound Controls (ADO and RDO) |
|
Writing a program that uses data-bound controls |
|
Data binding using ActiveX controls |
MFC ActiveX Controls: Using Data Binding in an ActiveX Control |
Distributing ActiveX controls |