ADO和DAO之间的区别 [英] Difference between ADO and DAO

查看:156
本文介绍了ADO和DAO之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是一个关于哪个更好的问题,而是一个关于为什么它们功能不同的问题。我遇到的问题已经处理了,但是我很好奇为什么会发生这种情况。



背景 - 使用Excel vba从Access数据库中提取数据。当用户单击按钮时,记录集将从Access中拉出,并将各种数据填充到电子表格中。然后,另一个记录集被从不同的查询中拉出,以填充电子表格的另一部分。



ADO的作用 - ADO对我的第一个记录集非常有用。但是,我的第二个记录集在Access中运行查询,运行并返回任何行。如果我在Access中运行这个查询,它会打开(约3到4秒)。此查询具有多个联接,计算项目,限制和可能的联合查询(我尝试了许多不同的方式,无/联合等)。我尝试关闭并重新打开ado连接。我尝试更改超时值,我甚至使用ADO命令来测试这个数据的Make表查询,然后从表中拉出来(这样做是有效的,但不是最好的情况,因为数据不断变化,而且我不想每次有人使用这个工具时都要运行make表查询)。



所以,我把第二个数据拉到DAO,看哪,它有效。第一个数据拉还是ADO(我通常喜欢使用),但现在考虑将其更改为DAO,因为我宁愿在代码中有一个数据访问方法。



那么,有人可以向我解释为什么ADO不会在一种情况下拉数据,但DAO会吗?再次,这纯粹是为了信息目的。

解决方案

DAO是Jet(Ms-Access)数据的本地数据访问方法表。 ADOActive X数据对象是几乎所有类型的数据库的行业友好的连接。



使用标准查询在这种情况下没有理由为什么ADO应该返回否DAO所做的记录,我怀疑这是查询还必须包含与Access数据库中项目相关的参数。如果是这种情况,那么ADO将无法使用,因为它不会使用所述参数,因为它只是Excel的外部引用,使用DAO方法将触发Access运行查询而不是Excel,因此它将能够访问它自己的参数/引用。


This is not a question about which is better, but rather a question regarding why they differ functionally. The problem I was running into has been handled, but I am curious as to why this behavior is happening.

Background - using Excel vba to pull data from an Access database. When user clicks a button, a recordset is pulled from Access, and it populates various data to the spreadsheet. Then, another recordset is pulled from a different query to populate another part of the spreadsheet.

What ADO does - ADO works great for my first recordset. However, my second recordset goes to the query in Access, runs, and returns no rows. If I run this query in Access, it does open up (after about 3 to 4 seconds). This query has multiple joins, computed items, limits, and possibly Union queries (I tried it many different ways, with/without union,etc.). I tried closing and reopening the ado connection. I tried changing timeout values, and I even tested using an ADO command to run Make table queries for this data, and then pull from the table instead (this worked by the way, but is not the best-case, since the data changes continually, and I do not want to have to run the make table query everytime someone uses this tool).

So, I changed the second data pull to DAO, and lo and behold, it works. The first data pull is still ADO (which I generally prefer to use), but am now considering changing it to DAO, because I would rather have one data access method in the code.

So, can someone explain to me why ADO will not pull the data in one case, but DAO will? Again, this is purely for informational purposes.

解决方案

DAO is the native data access method for the Jet (Ms-Access) data tables. ADO "Active X Data Objects" is an industry friendly connection to almost all types of database.

With a standard query there is no reason in this case why ADO should return no records where DAO does, I suspect it's that the query must also contain parameters relating to items within the Access database. If this is the case then ADO will not work as it will not have the option of using said parameters as it is just an external reference to Excel, using the DAO method will trigger Access to run the query rather than Excel and as such it will be able to access it's own parameters/references.

这篇关于ADO和DAO之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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