DataSetProvider - DataSet 到 ClientDataSet
编辑:似乎 DataSetProvider 没有该项目所需的功能,因此我将实现一个自定义类来将数据加载到 ClientDataSet 中。
我正在尝试从连接到我的数据库的 TMSQuery 获取数据,并使用 DataSetProvider 用其中一些数据填充 ClientDataSet。
我的问题是我需要修改其中一些数据才能进入我的 ClientDataSet。 ClientDataSet 具有与原始数据库数据不匹配的持久字段。我什至无法将数据库中的字符串放入 ClientDataSet 中的备注字段中。
ClientDataSet 是我的数据层的一部分,因此我需要逐个字段将数据库中的数据与 ClientDataSet 保持一致(大多数都能够直接通过,但许多需要路由和/或转换)。
有人有这方面的经验吗?
EDIT: It seems as if the DataSetProvider doesn't have the functionality I need for this project, so I'll be implementing a custom class for loading the data into the ClientDataSet.
I am trying to take data from a TMSQuery which is connected to my DB and populate a ClientDataSet with some of that data using a DataSetProvider.
My problem is that I will need to modify some of this data before it can go into my ClientDataSet. The ClientDataSet has persistent fields that will not match up with the raw DB data. I can't even get a string from the DB into a memo field in ClientDataSet.
The ClientDataSet is a part of my data tier so I will need to conform the data from the DB to the ClientDataSet field by field (well most will be able to go right through, but many will require routing and/or conversion).
Does anyone have experience with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找 TDataSetProvider.BeforeUpdateRecord 事件。为此事件编写一个事件处理程序,您可以手动控制如何将数据应用回数据库。
像这样的东西
You're looking for the TDataSetProvider.BeforeUpdateRecord event. Write an event handler for this event and you can take manual control of how the data is applied back to the data base.
Something like this
您可以通过实现 TDataSetProvider.OnGetData 事件来修改发送到 ClientDataSet 的数据。
当从 ClientDataSet 应用更新时,您可以使用 TDataSetProvider.OnUpdateData 事件。与 OnGetData 事件一样,您正在操作整个数据集而不是单个记录。
此 OnUpdateData 事件在 OnBeforeUpdateRecord 事件之前调用。此外,OnGetData 和 OnUpdateData 事件对整个数据集进行操作,而 OnBeforeUpdateRecord 对每个修改的记录调用一次。
You can modify the data going to the ClientDataSet by implementing the TDataSetProvider.OnGetData event.
When applying updates from the ClientDataSet you can use the TDataSetProvider.OnUpdateData event. Like the OnGetData event you are operating on the whole dataset rather than a single record.
This OnUpdateData event is called before the OnBeforeUpdateRecord event. Also the OnGetData and OnUpdateData events operate on the whole dataset while OnBeforeUpdateRecord is called once for each modified record.
如果我需要 ClientDataSet 来获取与数据库架构不完全匹配的数据,我会为 TQuery 组件编写一个查询,该查询以我想要的格式返回数据。然后,我为 TQuery 组件编写自己的单独的删除、插入、刷新和更新查询。
或者,您可以在数据库上创建一个视图并在 TQuery 组件中使用该视图。
如果您想要一个独立于数据库的自定义 ClientDataSet,那么您需要的是内存数据集。如果您没有内存数据集组件,请搜索“TClientDataSet 作为内存数据集”。不过,您最终得到的基本上是一个美化的列表视图组件。当然,您可以挂钩内存数据集的 OnUpdateRecord 以了解何时更新真实数据集。
If I need a ClientDataSet to have data that doesn't exactly match the database schema, I write a query for the TQuery component that returns the data in the format that I want. I then write my own, separate, Delete, Insert, Refresh, and Update queries for the TQuery component.
Alternatively, you could create a view on the database and use the view in your TQuery component.
If you want a custom ClientDataSet that is independent of the database, what you need is an in-memory dataset. If you don't have an in-memory dataset component, Google for "TClientDataSet as in-memory dataset". What you end up with though, is basically a glorified list view component. Of course, you can hook into the OnUpdateRecord of the in-memory dataset to know when to update your real dataset.