Share via


Data Access Programming (MFC/ATL)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Data Access Programming (MFC-ATL).

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 older technologies you can use for database programming in Visual C++. For information on data access programming using Visual C++ and SQL Server, see Data Access Using ADO.NET (C++/CLI), and Accessing data in Visual Studio.

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 Should I Use DAO or ODBC?
Using the Microsoft Knowledge Base to find additional articles on database topics written by product support engineers Microsoft Knowledge Base
ATL Database Support (OLE DB)
OLE DB programming (conceptual topics) OLE DB Programming Overview
Using the OLE DB consumer templates (conceptual topics) OLE DB Consumer Templates
OLE DB consumer attributes OLE DB Consumer Attributes
Using the OLE DB provider templates (conceptual topics) OLE DB Provider Templates
Adding an OLE DB consumer to an MFC project Creating an OLE DB Consumer
MFC Database Support (ODBC and DAO)
What DAO and ODBC are What Are DAO and ODBC?
When to use the MFC database classes When Should I Use the Database Classes?
Learn about the MFC database programming model What Is the MFC Database Programming Model?.
Choose between the MFC DAO classes and the MFC ODBC classes Should I Use DAO or ODBC?.
Data sources you can access with DAO and ODBC What Data Sources Can I Access with DAO and ODBC?
Open Database Connectivity (ODBC) ODBC and MFC
Whether you can call DAO or ODBC APIs directly while using the classes Can I Call DAO or ODBC Directly?
What ODBC drivers are provided ODBC Driver List
How the database classes work with the MFC document/view architecture MFC: Using Database Classes with Documents and Views
Installing MFC database support; what ODBC drivers are installed in Visual C++ by default; what ODBC and DAO SDK components are installed Installing MFC Database Support
Data-Bound Controls (ADO and RDO)
Writing a program that uses data-bound controls Data-Bound Controls (ADO and RDO)
Data binding using ActiveX controls MFC ActiveX Controls: Using Data Binding in an ActiveX Control
Distributing ActiveX controls MFC ActiveX Controls: Distributing ActiveX Controls

See Also

Data Access