DAO and MFC

MFC DAO数据库编程  10.3 MFC DAO数据库编程DAO(Database Access Object,数据访问对象)使用Microsoft Jet数据库引擎来访问数据库。MFC DAO封装了DAO的大部分功能,可以很方便地使用Microsoft Jet引擎访问数据库。本节就来介绍如何使用MFC DAO开发数据库应用程序。10.3.1 MFC DAO概述DAO适用于单系统应用程序或小范围本地分布 阅读详情

DAO and MFC

This article describes MFC's implementation of Microsoft Data Access Objects (DAO). Topics covered include:

  • How MFC Encapsulates DAO
  • Mapping of DAO objects to MFC classes
  • Key differences between MFC and DAO
  • Further reading about the MFC DAO classes
Note   Whether you use the MFC DAO classes or the MFC ODBC classes depends on your situation and your needs. For a discussion of the differences between the two and guidance on choosing one, see the article Database Topics (DAO).

How MFC Encapsulates DAO

The MFC DAO classes treat DAO much as the MFC classes for programming Windows treat the Windows API: MFC encapsulates, or "wraps," DAO functionality in a number of classes that correspond closely to DAO objects. Class CDaoWorkspace encapsulates the DAO workspace object, class CDaoRecordset encapsulates the DAO recordset object, class CDaoDatabase encapsulates the DAO database object, and so on.

MFC's encapsulation of DAO is thorough, but it is not completely one-for-one. Most major DAO objects do correspond to an MFC class, and the classes supply generally thorough access to the underlying DAO object's properties and methods. But some DAO objects, including fields, indexes, parameters, and relations, do not. Instead, the appropriate MFC class provides an interface, via member functions, through which you can access, for example:

  • The fields of a recordset object
  • The indexes or fields of a table
  • The parameters of a querydef
  • The relations defined between tables in a database

Mapping of DAO Objects to MFC Classes

The following tables show how DAO objects correspond to MFC objects. MFC Classes and Corresponding DAO Objects shows the MFC classes and the DAO objects they encapsulate. How MFC Manages DAO Objects Not Mapped to Classes shows how MFC deals with DAO objects that do not map directly to an MFC class.

Note   MFC now supports DAO 3.5. MFC DAO classes work either with DAO 3.0 or DAO 3.5, but have not been designed to take advantage of any new DAO 3.5 features, including ODBCDirect.

MFC Classes and Corresponding DAO Objects

ClassDAO objectRemarks
CDaoWorkspaceWorkspaceManages a transaction space and provides access to the database engine.
CDaoDatabaseDatabaseRepresents a connection to a database.
CDaoTableDefTabledefUsed to examine and manipulate the structure of a table.
CDaoQueryDefQuerydefUsed to store queries in a database. You can create recordsets from a querydef or use it to execute action or SQL pass-through queries.
CDaoRecordsetRecordsetUsed to manage a result set, a set of records based on a table or selected by a query.
CDaoExceptionErrorMFC responds to all DAO errors by throwing exceptions of this type.
CDaoFieldExchangeNoneManages exchange of data between a record in the database and the field data members of a recordset.

How MFC Manages DAO Objects Not Mapped to Classes

DAO objectHow MFC manages it
FieldObjects of classes CDaoTableDef and CDaoRecordset encapsulate fields and supply member functions for adding them, deleting them, and examining them.
IndexObjects of classes CDaoTableDef and CDaoRecordset encapsulate indexes and supply member functions for managing them. Tabledefs can add, delete, and examine indexes. Tabledefs and recordsets can set or get the currently active index.
ParameterObjects of class CDaoQueryDef encapsulate parameters and supply member functions for adding them, deleting them, examining them, and getting and setting their values.
RelationObjects of class CDaoDatabase encapsulate relations and supply member functions for adding them, deleting them, and examining them.

DAO Objects Not Exposed in MFC

MFC and DAO do not supply abstractions for some objects used within Microsoft Access: Application, Container, Control, Debug, Document, Form, Module, Report, Screen, and Section. If you create a Microsoft Access database and manipulate it from an MFC application, you can't access those objects through code.

MFC doesn't supply classes or interfaces to the DAO group and user objects — to work with DAO security, you must write your own code.

MFC also doesn't encapsulate DAO property objects, except that the MFC DAO classes do give you access to the properties of all exposed objects.

MFC does give you access to DAO's DBEngine object, through class CDaoWorkspace.

Accessing the Unexposed DAO Objects

The unexposed objects listed above can be accessed in two ways:

  • Outside the MFC classes by using the non-MFC C++ classes provided in the DAO SDK.
  • Inside the MFC classes by calling DAO directly through a DAO interface pointer supplied by one of the MFC classes. For information, see Technical Note 54.

Key Differences Between MFC and DAO

MFC's version of data access objects differs from the underlying structure of DAO in some ways.

How MFC Accesses the Database Engine

DAO has a DBEngine object that represents the Microsoft Jet database engine. The DBEngine object provides properties and methods you can use to configure the database engine.

In MFC, there is no DBEngine object. Access to important properties of the database engine is supplied via class CDaoWorkspace. To set or get these properties, call any of the static member functions of CDaoWorkspace. For more information, see the articles DAO Workspace: The Database Engine and DAO Workspace: Accessing Properties of the Database Engine.

MFC Flattening of the DAO Object Hierarchy

Because MFC doesn't supply a class for every DAO object, the effect is that the DAO object hierarchy is somewhat "flattened" in MFC. The main examples of this flattening are:

  • Putting access to the database engine in class CDaoWorkspace rather than in a database engine class.
  • Encapsulating DAO field, index, parameter, and relation objects inside the classes that represent their owning objects. For example, access to fields is encapsulated in classes CDaoTableDef and CDaoRecordset. For information, see the table How MFC Manages DAO Objects Not Mapped to Classes.

MFC and DAO Security

MFC does not encapsulate the DAO user and group objects in any way, which means that MFC doesn't provide DAO's security functionality.

You can still use DAO security from your MFC applications, but you will have to call DAO directly, using the m_pDAOWorkspace data member of class CDaoWorkspace. That member is a pointer to an interface that gives access to a DAO workspace object's methods and properties. For information about calling DAO directly, see Technical Note 54.

MFC does allow password protection via various MFC classes. For example, when you create a CDaoWorkspace object, you can specify a password to protect the database(s) that the workspace contains. To use this functionality, a SYSTEM.MDW file must be available to the database engine on the machine running your application. If no SYSTEM.MDW file is available to the database engine, your application cannot use any of the security features. For information about the SYSTEM.MDW file, see the topic "Permissions Property" in DAO Help.

Further Reading About the MFC DAO Classes

To learn more about using the MFC DAO classes, see the following articles (in the order listed here):

  • DAO: Writing a Database Application
  • DAO: Database Tasks
  • DAO: Creating, Opening, and Closing DAO Objects
  • DAO Workspace
  • DAO Database
  • DAO Database: Using Workspaces and Databases
  • DAO Recordset
  • DAO Record Field Exchange (DFX)
  • DAO Querydef
  • DAO Tabledef
  • DAO Workspace: Managing Transactions
  • DAO Collections
  • DAO External: Working with External Data Sources (primarily ODBC)
  • DAO Workspace: The Database Engine
  • DAO: Using DAO in DLLs
  • Exceptions: Database Exceptions
  • Record Views
Tip   From any of the MFC help topics in this documentation set, you can get to a topic called DAO: Where Is..., which helps you navigate online to the topics that you need. The topic is always available via the See Also button in the topic window.
vc6.0使用DAO访问access2000的问题 感觉DAO已经是一种比较旧的数据库技术,但我的一个同学还在使用VC6.0跟mfc的DAO类来操作access2000,并遇到了一个问题,就是程序运行时提示说“无法识别数据库格式”。查了一下原因,应该是这样的:VC6.0里面的mfc默认使用的是DAO3.5,而DAO3.5使用的数据库引擎是Jet3.5,Jet3.5操作access97是没有问题的,而操作access2000却不行,因为acces 阅读详情

相关推荐

mfc和mysql连接 dao_MFC,C与C++程序与MySql数据库连接 ——陈绍钦 csq

很多种方法在C++程序里利用数据库:ODBC、DB、DAO、ADO、API等,ODBC是传统的方法功能强大,ADO比较便捷,并逐渐代替了DAO。对于mysql数据库来说,其提供的API函数和PHP中mysqli函数相差不大,毕竟mysql是用c语言写的,可以说懂得了PHP和mysql的结合,就懂得了c++与mysql的结合。以下是C++程序里利用mysql数据库的简略说明。一、MySQL的安装可以...

weixin_33324197的博客 468

DAO简介(MFC)

1 DAO简介       DAO(数据访问对象)是一种应用程序编程接口(API),存在于微软的Visual Basic中,它允许程序员请求对微软的Access数据库的访问。DAO是微软的第一个面向对象的数据库接口。DAO对象封闭了Access的Jet函数。通过Jet函数,它还可以访问其他的结构化查询语言(SQL)数据库。在VC中,它是从Visual C++4.0版开始引入的。 2 D

MannHello的专栏 2235

深入理解MFC数据库编程:ODBC与DAO技术

本文深入探讨了MFC(Microsoft Foundation Classes)在数据库编程中的应用,特别是ODBC(Open Database Connectivity)和DAO(Data Access Objects)API的使用。通过实例分析,展示了如何利用MFC的文档/视图架构与ODBC和DAO包装类来创建一个地址簿应用程序,包括获取数据、更新应用程序变量、以及如何通过AppWizard简化开发过程。

weixin_36019375的博客 360

MFC DAO编程总结

一半情况下,并不需要直接使用CDaoDatabase对象,因为CDaoRecordSet对象可以是实现大多数功能,但是,在进行事务(Transaction)处理时,CDaoDatabase就起到关键作用。使用CDaoDatabase构造一个对象,并调用Open成员函数打开数据源的连接,接着构造CDaoRecordSet对象以操作连接的数据源,并向CDaoDatabase对象传递记录集构造程序指针。注意:MFC DAO仅用来支持Access数据库,应用范围相对固定。

jiandaxiami的博客 289

MFC数据库编程:ODBC和DAO的封装与实现

本章详细介绍了如何使用MFC提供的ODBC和DAO API封装类来创建一个通讯录应用程序。通过实例演示了如何将数据绑定到应用程序,并使用MFC AppWizard创建数据绑定。本章内容涵盖了从设置数据源、创建数据支持到利用MFC的文档/视图架构实现数据与视图的绑定。

weixin_36019375的博客 470

全面掌握MFC在C++中的应用与技巧

本文还有配套的精品资源,点击获取 简介:《深入浅出MFC(C++)》旨在提供对微软基础类库(MFC)的全面解析,帮助开发者高效开发Windows应用程序。书中详尽介绍了MFC的基础结构、框架类、消息处理机制、文档/视图架构、DLL支持、数据库编程、国际化、异常处理和网络编程等关键知识点,致力于提升开发者在这些领域的专业技能。 1. MFC基本概念与初始化 1...

weixin_35705784的博客 2693

MFC中使用DAO来打开数据库

最近在学习MFC中数据库的使用,在之前写过一篇使用使用Access技术连接数据库。在这个项目中打开的是.mdb数据库文件。ODBC是数据库的连接接口,他不管连接是何种数据库,在程序运行过程中都会提供选定数据库的引擎。点击打开MDB文件后,选择要打开的MDB文件,然后显示数据库中的表,如图所示。这个例子的思路是:在文档类中打开数据库,并读取其中的数据,然后保存起来。这个例子中其中CDAOTestView继承于一个自定义的CRowView,这个CRowView的试图类是一个纯虚类,负责数据的处理和显示。

weixin_45144862的博客 1297

演示如何用MFC和DAO(数据访问对象)写一个CGI扩展服务器,程序动

演示如何用MFC和DAO(数据访问对象)写一个CGI扩展服务器,程序动态生成一个网页显示数据库中的前三条记录(8KB)

C++连接SQL SERVER 数据库方式

1、ODBC ODBC(Open DataBase Connectivity)开放数据库互联。是由微软主导的数据库链接标准; ODBC是一个访问数据库的底层接口,想要使用ODBC必须提供驱动,sqlserver 提供SQL Server Native Client ODBC driver来支持ODBC接口。 只能用户关系型数据库,很难用于对象数据库及其他非对象数据库。 ODBC访问sqls...

weixin_34080903的博客 1322

mfc DAO连接access数据库

mfc DAO连接access数据库 可添加,删除记录!

MFC DAO编程函数一览

这是我自己总结的MFC DAO编程中,CDaoWorkspace CDaoDatabase CDaoTableDef CDaoQueryDef CDaoRecordset五个类的成员函数,比较全。

SQL Server MFC DAO类和MFC ODBC类

转自:http://www.verybc.com/a/shujuku/20091125/9828.html时间:2009-11-25 00:26来源:作者:点击:347次内容概要:大多数 mfc 开发人员都熟悉开放式数据库连接 (odbc) 数据库类 - 它们早在三年半以前就出现了。在 mfc 4.2 中,对这些类有一些重要的 大多数 mfc 开发都熟悉开放式数据库连接 (odbc) 数据库类 - 它们早在三年半以前就出现了。在 mfc 4.2 中,对这一些类有一些很重要的改进。<br />身为 c++ 开

Nicholas的专栏 QQ1295794532 1130

python代码爬取大众点评评论!直接copy就可以运行!

python代码爬取大众点评评论!直接copy就可以运行!

QiuQiRuQin的博客 1万+

mfc和mysql连接 dao_DAO简介(MFC) .

1 DAO简介DAO(数据访问对象)是一种应用程序编程接口(API),存在于微软的Visual Basic中,它允许程序员请求对微软的Access数据库的访问。DAO是微软的第一个面向对象的数据库接口。DAO对象封闭了Access的Jet函数。通过Jet函数,它还可以访问其他的结构化查询语言(SQL)数据库。在VC中,它是从Visual C++4.0版开始引入的。2 DAO和ODBC的比较2.1 ...

weixin_35064481的博客 296

BIOS更新后PIN不可用怎么办?从原理到实操的完整修复指南

在计算机维护中,BIOS更新是常见的固件升级操作,但其引发的登录异常却常让用户措手不及。Windows Hello PIN并非传统密码,它通过TPM芯片与设备启动环境(PCR状态)强绑定,一旦主板固件或安全启动配置改变,TPM便会拒绝释放密钥,导致“由于此设备上的更改,你的PIN不再可用”。理解这一原理后,恢复路径清晰可控:优先尝试密码登录,或通过WinRE替换utilman.exe创建临时管理员,必要时还需处理BitLocker恢复密钥。本文面向系统维护与数据安全场景,系统梳理PIN失效的恢复流程与避坑方

weixin_31364787的博客 417

Caffeine:为每个元素动态设置过期时间

Caffeine利用expireAfter方法实现为每个元素动态设置过期时间

大数据开发、JAVA开发、人工智能AI 1万+

java中dao_java中的Dao类是什么意思?

展开全部DAO(Data Access Object)数据访问对象是一个面向对象的数据库接口,它显露了 Microsoft Jet数据库引擎(由62616964757a686964616fe58685e5aeb931333366303062 Microsoft Access 所使用),并允许 Visual Basic 开发者通过 ODBC 像直接连接到其他数据库一样,直接连接到 Access ...

weixin_36329071的博客 4321

数字孪生模型构建理论及应用

源自:计算机集成制造系统作者:陶飞 张贺 戚庆林 徐 俊 孙铮 胡天亮 刘晓军 刘庭煜 关俊涛 陈畅宇 孟凡伟 张辰源 李志远 魏永利 朱铭浩 肖斌数字孪生作为实现数字化转型和促进智能化升级的重要使能途径,一直备受各行各业关注,已从理论研究走向了实际应用阶段。数字孪生是以多维虚拟模型和融合数据双驱动,通过虚实闭环交互,来实现监控、仿真、预测、优化等实际功能服务和应用需求,其中数字孪生模型构建是实现数字孪生落地应用的前提。

renhongxia1的博客 1万+

MFC DLL——Regular DLL and Extension DLL

2  MFC DLL——扩展的和正规的MFC的AppWizard可以让我们创建MFC库支持的两种DLL:扩展的DLL和正规的DLL。这两种类型的区别是什么呢?说明:当然,Developer Studio也让我们创建纯的、与MFC库无关的Win32 DLL,就像它让我们创建与

delphiwcdj的专栏 5010

unity游戏开发日志(一)将mmd模型导入unity,并解决材质丢失的问题

unity音乐游戏开发,导入角色模型并解决材质问题

yizhigou1的博客 1773

AD9371 官方例程构建及单音信号收发

项目构建基本流程和AD9361差不多,由于官方使用的ZCU102,记录下移植遇到的一些问题最终接收到正确的正弦波Errors: 0Errors: 0Errors: 0Errors: 0AD9361。

weixin_44630490的博客 2976

使用ODBC还是DAO

从 Visual C++ .NET 起,Visual C++ 环境和向导不再支持 DAO(不过提供了 DAO 类,仍可供您使用)。Microsoft 建议对新项目使用 OLE DB 模板或 ODBC。DAO 只应用于维护现有的应用程序。 使用哪一

652

双像素传感器的AI计算摄影实战:单目深度估计与图像去模糊的融合创新

本文介绍了双像素传感器技术在计算机视觉中的应用,包括深度估计、图像去模糊和图像重建等任务。双像素传感器通过两个子单元捕捉视差信息,使摄像头能够分析场景的三维结构和运动轨迹。文章以图像去模糊为例,详细展示了从数据准备到模型训练的完整流程,包括构建自定义数据集、设计双像素特征提取模块、训练去模糊模型及推理测试。通过模拟双像素的"双视角"信息融合,该AI算法能有效恢复模糊图像的清晰细节。

know_F0727的博客 260

DAO在MFC中的应用实例

本文介绍使用MFC DAO访问数据库的一个实例,其中实例来源于网络。  实例同样实现了对数据库的基本操作:添加、修改、删除和遍历。与ODBC实例中不同的是,ODBC使用过程中添加了一个从CRecordset派生而来的CBook类,负责成员数据与数据表字段的关联,而本实例则是直接使用CDaoRecordset类。无论是使用ODBC还是DAO访问数据库都可以使用这两种方法,本实例采用后者来实现

MannHello的专栏 1204

【小白CV教程】YOLOv5+Deepsort实现车辆行人的检测、追踪和计数

【小白CV教程】YOLOv5+Deepsort实现车辆行人的检测、追踪和计数本文禁止转载!项目简介:YOLOv5检测器:DeepSort追踪器:运行demo:训练自己的模型:调用接口:创建检测器:调用检测接口: 本文禁止转载! 项目简介: 使用YOLOv5+Deepsort实现车辆行人追踪和计数,代码封装成一个Detector类,更容易嵌入到自己的项目中。 代码地址(欢迎star): https://github.com/Sharpiless/Yolov5-deepsort-inference 最终效果:

梁瑛平的博客 5万+

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

【MFC-数据库无法对DAO/Jet db引擎进行初始化】2020-11-02

问题1描述:当编译运行MFC后,软件提示如下错误: 原因分析: 解决方法: 手动注册DAO350.DLL和MSJET35.Dll

千帆少年靓 4065

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

上一篇: 10.9 自动注册DSN和创建表
下一篇: ^_-诚征BLOG友情连接
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址