在 Access 2007 中使用 ADO 还是 DAO 更好? [英] Is it better to use ADO or DAO in Access 2007?

查看:54
本文介绍了在 Access 2007 中使用 ADO 还是 DAO 更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Access 2007 中创建新数据库时,应该使用 ADO(ActiveX 数据对象)还是 DAO(数据访问对象)?

When creating a new database in Access 2007, should ADO (ActiveX Data Objects) or DAO (Data Access Objects) be used?

此数据库的一部分将从 Excel 2007 电子表格中导入数据.

Part of this database will be importing data from Excel 2007 spreadsheets.

推荐答案

[根据记录,曾经是Jet"的官方名称现在是Access 数据库引擎".]

[For the record, the official name for what once was 'Jet' is now the 'Access database engine'.]

对于 ACE(Access2007 引擎 .accdb 格式)功能,它必须是 ACEDAO.

For ACE (the Access2007 engine .accdb format) features it has to be ACEDAO.

对于 Jet 4.0 功能,它必须是 ADO 经典版.

For Jet 4.0 features it has to be ADO classic.

对于 Jet 3.51 及更早版本的功能,选择 ADO 或 DAO.两者都有优点和缺点.绝大多数 Access 数据库引擎功能对两者都是通用的;相互排斥的功能是有争议的边缘.也许是一种生活方式的选择,但没什么大不了的.聪明的编码器使用了两者的优点:)

For Jet 3.51 features and earlier, pick either ADO or DAO. There are advantages and disadvantages to both. The vast majority of Access database engine functionality is common to both; the mutually exclusive functionality is arguable fringe. A lifestyle choice, perhaps, but no big deal. The smart coder uses the best of both :)

我使用了很多,ADO 是我个人的偏好.它比 DAO 更现代,所以在架构上它是一个改进:更扁平的对象模型,没有 DAO 的拆卸问题等.更多的属性和方法并引入了事件(DAO 没有),例如用于异步连接和获取记录.ADO 记录集可以断开连接、分层和编造,而 DAO 记录集则不能.基本上,他们采用了 DAO 的优点并使其变得更好.

I've used both quite a bit and ADO is my personal preference. It is more modern than DAO, so architecturally it is an improvement: flatter object model, none of the tear down problems of DAO, etc. More properties and methods and introduces events (DAO has none) e.g. for asynchronous connection and fetching of records. ADO recordsets can be disconnected, hierarchical and fabricated, DAO recordsets cannot. Basically, they took the good things about DAO and made them better.

DAO 并非没有优点.一方面,您会发现比 ADO for Access/Jet 更多的 DAO 代码示例.

DAO is not without its strong points. For one, you will find more DAO code examples than ADO for Access/Jet.

附言出于某种原因,喜欢 DAO 的人真的不喜欢 ADO.无视宣传.ADO 没有被弃用.ACE 有一个 OLE DB 提供程序,并且是目前在 64 位中使用 ACE 的唯一方法.ADO.NET 并没有取代 ADO 经典版,就像 VB.NET 在 Access 项目中取代 VBA6 一样.

P.S. for some reason, folk who like DAO really dislike ADO. Ignore the propaganda. ADO isn't deprecated. The ACE has an OLE DB provider and is currently the only way of using ACE in 64 bit. ADO.NET hasn't replaced ADO classic any more than VB.NET has replaced VBA6 in Access projects.

只是为了澄清,对于 Jet 4.0 功能,它必须是 ADO 经典版",这是因为 DAO 3.6 仅针对 Jet 4.0 的新功能进行了一些增强.例如,对于 DECIMAL 数据类型,您不能指定小数位数/精度.DAO 完全没有其他功能.例如,您能否在 Jet 4.0 中使用 DAO(或 ACE 中的 ACEDAO)执行以下操作?

just to clarify, "For Jet 4.0 features it has to be ADO classic," this is because DAO 3.6 only received a few enhancements for the features new to Jet 4.0. For example, for the DECIMAL data type you cannot specify scale/precision. Other features are missing completely from DAO. For example, can you do the following in Jet 4.0 using DAO (or ACEDAO in ACE for that matter)?

CREATE TABLE Test (
   col1 CHAR(4) WITH COMPRESSION DEFAULT '0000' NOT NULL, 
   CHECK (NOT EXISTS (
                      SELECT T1.col1 
                        FROM Test AS T1 
                        WHERE T1.col1 <> '0000' 
                        GROUP 
                           BY T1.col1 
                       HAVING COUNT(*) > 1
                      ))
);

(提示:具有表级数据完整性约束的可压缩固定宽度文本列.)不,您不能.

(hint: compressible fixed-width text column with table-level data integrity constraint.) No, you cannot.

AFAIK 对 ACEDAO 的唯一增强是新的 ACE 功能,即它们没有回过头来填补 DAO 中 Jet 4.0 的空白.他们为什么要这样做?我们仍然有 ADO 来填补空白.最好让团队更高效地花费时间,比如修复烦人的 DECIMAL 排序错误,对我来说 ACE 最好的事情是 ;-)

AFAIK the only enhancements to ACEDAO was for the new ACE functionality i.e. they didn't go back and fill in the Jet 4.0 gaps in DAO. And why should they? We still have ADO to plug the gaps. Better that the team spent their time more productively, like fixing that annoying DECIMAL sort bug, for me the best thing about ACE ;-)

这篇关于在 Access 2007 中使用 ADO 还是 DAO 更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆