既然是三层结构,那么就应该用NestDataSet来表示主从关系。这样数据只要从服务器读取一次就可以了。下次再看就是Cache在内存中的记录了。

解决方案 »

  1.   

    是的,对于这样的三个TABLE组成的主细表关系应该用NESTDATASET来表示;
    但是,更建议你能用QUERY,不要用太多的TABLE,QUERY对绶存的记录能够更好的应用;
      

  2.   

    我的程序是三层架构数据库,客户端程序中用Query合适吗?
    这种场合用Query和ClientDataset的区别何在?
      

  3.   

    客户端用QUery,意味着你发布客户端就要发布BDE。失去了三层的意义。另外ClientDataset功能强大,是Borland的一个特色。
      

  4.   

    我的客户端DCOMConnection,ClientDataset,服务器端ADODAtaset,dataProvider.有没有直接在现有基础上做些修改,解决这个问题的途径?如果采用NESTDATASET
    ,需要做何改动?
      

  5.   

    我的客户端使用的是DCOMConnection,ClientDataset组件,服务器端使用的是ADODAtaset,dataProvider组件. 有没有直接在现有基础上做些修改,不删除这些组件,通过改变属性,或者代码控制,解决这个问题的途径?
    如果采用NESTDATASET ,又需要对程序做何改动?够明白了吧
      

  6.   

    讲起来有些烦琐。下面是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 .
      

  7.   

    很好,我慢慢看,
    还有没有别的办法?
    我对 ClientDataset,ADODAtaset已经分别进行了设置,为何不行?
    再有,为何有时候,只有第一个主表纪录可以看到从表相关纪录,而主表转到
    下一个记录的时候,就看不到从表记录了?
      

  8.   

    在这种情况下,每一个从表都是主表的一个Field(是否理解?)。在缺省的状况下,Delphi会自动从服务器Fetch从表的记录(如果已经Fetch过,那么就不用Fetch了)。
    这样,无论你怎么移动主表的记录指针,从表都对应于相应的主表记录。因为此时从表是主表的一个Field。
      

  9.   

    上面讲的就有点小儿科了,这个我还是明白的。
    我的问题在于,这个主细关系不能在逻辑上很好的显示,主表除第一个记录外,其他记录的从记录集都不显示。这个怎样解决?而有些情况下,虽然都显示,但实显示的很有问题,随着DBnavigator控件的翻滚,从表数据记录成倍增加,不过我认为,这是主表重复从服务器取得从表数据,并插入原来数据集缓冲区中,不过这个问题如何解决,我不很清楚。
    在线的朋友有没有比较好的解决办法?
      

  10.   

    如果真的不行的话,你可以在从表里进行写啊;
    你把那个从表改成clientdataset;
    在里边写commondtext;
      

  11.   

    用dev公司的masterview控件,可以表达无限层次的主次结构。