讲起来有些烦琐。下面是D6DG的文章节选,你读一读吧。 One option for master/detail relationships is nested datasets. Nested datasets allow a master table to actually contain detail datasets. In addition to updating master and detail records in one transaction, they allow for storage of all master and detail records to be stored in one briefcase file, and you can use the enhancements to DBGrid to pop up detail datasets in their own win-dows. A word of caution if you do decide to use nested datasets: All the detail records will be retrieved and brought over to the client when selecting a master record. This will become a possible performance bottleneck if you nest several levels of detail datasets. For example, if you retrieve just one master record that has 10 detail records, and each detail record has three detail records linked to the first level detail, you would retrieve 41 records initially. When using client-side linking, you would only retrieve 14 records initially and obtain the other grandchild records as you scrolled through the detail TClientDataSet . In order to set up a nested dataset relationship, you need to define the master/detail relationship on the application server. This is done using the same technique you’ve been using in client/ server applications—namely, defining the SQL statement for the detail TQuery , including the link parameter. Here’s an example: “select *orders where custno=:custno ” You then assign the TQuery.Datasource for the detail TQuery to point to a TDatasource com-ponent that’s tied to the master TDataset . Once this relationship is set up, you only need to export the TDatasetProvider that’s tied to the master dataset. DataSnap is smart enough to understand that the master dataset has detail datasets linked to it and will therefore send the detail datasets across to the client as a TDatasetField . On the client, you assign the master TClientDataset.ProviderName property to the master provider. Then, you add persistent fields to the TClientDataset . Notice the last field in the Fields Editor. It contains a field named the same as the detail dataset on the server and is declared as a TDatasetField type. At this point, you have enough information to use the nested dataset in code. However, to make things really easy, you can add a detail TClientDataset and assign its DatasetField property to the appropriate TDatasetField from the master. It’s important to note here that you didn’t set any other properties on the detail TClientDataset , such as RemoteServer , ProviderName , MasterSource , MasterFields ,or PacketRecords . The only property you set was the DatasetField property. At this point, you can bind data-aware controls to the detail TClientDataset as well. After you’ve finished working with the data in the nested dataset, you need to apply the updates back to the database. This is done by calling the master TClientDataset ’s ApplyUpdates()method. DataSnap will apply all the changes in the master TClientDataset , which includes the detail datasets, back to the server inside the context of one transaction. You ’ll find an example on the book’s CD-ROM in the directory for this chapter under \NestCDS .
但是,更建议你能用QUERY,不要用太多的TABLE,QUERY对绶存的记录能够更好的应用;
这种场合用Query和ClientDataset的区别何在?
,需要做何改动?
如果采用NESTDATASET ,又需要对程序做何改动?够明白了吧
One option for master/detail relationships is nested datasets. Nested datasets allow a master
table to actually contain detail datasets. In addition to updating master and detail records in one
transaction, they allow for storage of all master and detail records to be stored in one briefcase
file, and you can use the enhancements to DBGrid to pop up detail datasets in their own win-dows.
A word of caution if you do decide to use nested datasets: All the detail records will be
retrieved and brought over to the client when selecting a master record. This will become a
possible performance bottleneck if you nest several levels of detail datasets. For example, if
you retrieve just one master record that has 10 detail records, and each detail record has three
detail records linked to the first level detail, you would retrieve 41 records initially. When
using client-side linking, you would only retrieve 14 records initially and obtain the other
grandchild records as you scrolled through the detail TClientDataSet .
In order to set up a nested dataset relationship, you need to define the master/detail relationship
on the application server. This is done using the same technique you’ve been using in client/
server applications—namely, defining the SQL statement for the detail TQuery , including the
link parameter. Here’s an example:
“select *orders where custno=:custno ”
You then assign the TQuery.Datasource for the detail TQuery to point to a TDatasource com-ponent
that’s tied to the master TDataset . Once this relationship is set up, you only need to
export the TDatasetProvider that’s tied to the master dataset. DataSnap is smart enough
to understand that the master dataset has detail datasets linked to it and will therefore send the
detail datasets across to the client as a TDatasetField .
On the client, you assign the master TClientDataset.ProviderName property to the master
provider. Then, you add persistent fields to the TClientDataset . Notice the last field in the
Fields Editor. It contains a field named the same as the detail dataset on the server and is
declared as a TDatasetField type. At this point, you have enough information to use the
nested dataset in code. However, to make things really easy, you can add a detail
TClientDataset and assign its DatasetField property to the appropriate TDatasetField
from the master. It’s important to note here that you didn’t set any other properties on the detail
TClientDataset , such as RemoteServer , ProviderName , MasterSource , MasterFields ,or
PacketRecords . The only property you set was the DatasetField property. At this point, you
can bind data-aware controls to the detail TClientDataset as well.
After you’ve finished working with the data in the nested dataset, you need to apply the
updates back to the database. This is done by calling the master TClientDataset ’s
ApplyUpdates()method. DataSnap will apply all the changes in the master TClientDataset ,
which includes the detail datasets, back to the server inside the context of one transaction.
You ’ll find an example on the book’s CD-ROM in the directory for this chapter under
\NestCDS .
还有没有别的办法?
我对 ClientDataset,ADODAtaset已经分别进行了设置,为何不行?
再有,为何有时候,只有第一个主表纪录可以看到从表相关纪录,而主表转到
下一个记录的时候,就看不到从表记录了?
这样,无论你怎么移动主表的记录指针,从表都对应于相应的主表记录。因为此时从表是主表的一个Field。
我的问题在于,这个主细关系不能在逻辑上很好的显示,主表除第一个记录外,其他记录的从记录集都不显示。这个怎样解决?而有些情况下,虽然都显示,但实显示的很有问题,随着DBnavigator控件的翻滚,从表数据记录成倍增加,不过我认为,这是主表重复从服务器取得从表数据,并插入原来数据集缓冲区中,不过这个问题如何解决,我不很清楚。
在线的朋友有没有比较好的解决办法?
你把那个从表改成clientdataset;
在里边写commondtext;