使用 ClientDataSet 连接 Delphi ADOQuery 结果
我编写了一个应用程序,允许用户定义查询,使用 TADOQuery 组件运行它,并将报告作为 XML 文档保存到他们的 PC(SaveAsFile 将 pfXML 作为 Format 参数传递)以供离线查看。这很好用。
我现在需要做的就是连接结果。我的意思是,我需要获得至少两个报告(具有相同的字段,因为它们使用相同的查询)并将它们连接在一起以生成一份报告。例如: 假设我有一个检索用户列表的查询。我在“系统 A”和“系统 B”上运行此查询,其中系统 A 和系统 B 是两个独立的系统。在两个系统上运行查询后,我就有了两个单独的报告文件,我可以将它们加载回 TADOQuery 组件,然后在屏幕上查看。不过,我需要做的是将报告连接在一起,这样我就可以同时在屏幕上看到所有结果,而不必在两个报告之间切换。
有人告诉我可以使用 TClientDataSet 来完成此操作,但我对数据库编程相对较新,并且不知道从哪里开始。我已经查看了 http://delphi.about.com/ 上的文章od/usedbvcl/a/tclientdataset.htm 但我仍然一无所知,因为似乎没有什么能完全满足我需要它做的事情。
因此我有两个问题: 1. 使用 TClientDataSet 是获取两个单独结果集并将它们连接起来的最佳方法吗?如果有更好的方法来做到这一点,它是什么? 2. 如果使用 TClientDataSet 是执行此操作的最佳方法,那么我到底该如何执行此操作?如何将数据从 TADOQuery 传输到 TClientDataSet,然后再传输回来?处理的基本流程需要如下所示:
Report 1 (LoadFromFile) -> TADOQuery \
ClientDataSet -> TADOQuery -> SaveToFile
报告 2 (LoadFromFile) -> TADOQuery /
所有帮助将不胜感激。我真的不知道从哪里开始!
I have written an application that allows a user to define a query, run it using a TADOQuery component, and save the report to their PC as an XML document (SaveAsFile passing in pfXML as the Format parameter) for offline viewing. This works fine.
What I now need to do is concatenate the results. What I mean by this is that I need to get at least two reports (with identical fields as they are using the same query) and join them together to make one report. For example:
Say I have a query that retrieves a list of users. I run this query on "System A" and "System B" where System A and System B are two separate systems. Once I have run the query on both systems, I have two separate report files, which I can load back into a TADOQuery component and then view on screen. What I need to do though is join the reports together, so instead of having to switch between the two reports, I can see all the results on screen at the same time.
I have been told that I can do this using a TClientDataSet but I'm relatively new to database programming and have no idea where to start with this. I've checked out the articles at http://delphi.about.com/od/usedbvcl/a/tclientdataset.htm but I'm still in the dark as nothing seems to do exactly what I need it to do.
I therefore have two questions:
1. Is using a TClientDataSet the best way to take two separate result sets and concatenate them? If there is a better way to do this, what is it?
2. If using a TClientDataSet is the best way to do this, how exactly would I go about doing this? How do you transfer data from a TADOQuery into a TClientDataSet and then back again? The basic flow of the processing needs to go something like this:
Report 1 (LoadFromFile) -> TADOQuery \
ClientDataSet -> TADOQuery -> SaveToFile
Report 2 (LoadFromFile) -> TADOQuery /
All help would be appreciated on this. I really don't know where to start!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚调查完这个。我的应用程序允许用户通过查询数据库来生成报告。我可以让它工作,并且对于小型结果集非常有效 - 但是,由于这是一个报告应用程序,并且完全有可能返回数十万条记录,因此使用 ClientDataSet 会带来巨大的性能问题。一旦您获得超过大约 50,000 条记录(考虑到客户群,这是合理的),处理量就会开始呈指数级增长,因此现在这基本上没有实际意义。
I've just about finished looking into this. My application allows the user to generate reports by querying their databases. I can get this to work and it is very efficient for small result sets - however, as this is a reporting application, and it's entirely possible that hundreds of thousands of records can be returned, using a ClientDataSet gives massive performance problems. Once you get above around 50,000 records (reasonable, given the customer base), processing starts to increase exponentially, so this is now basically moot.