可以在服务器一段设置。
你的代码似乎是在客户端设置M/D结构,因此需要配置mastersource等属性。

解决方案 »

  1.   

    还有cds2还需要传递参数给服务器。
      

  2.   

    轻舞飞扬在吗?快help我~
    自己up
      

  3.   

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

  4.   

    小例子在demo里就应该有你尝试用两个table控件,分别对应两个datasourc和主从表。然后在从表的datasource中选择mastersource是主表的datasource。那么简单的主从连接就建立了。如果要用query的话,则需要传递参数。这在李维的书上就有说明的
      

  5.   

    可是,现在的问题是,我是用的ADO方式,并且C/S模式的。客户程序中应该怎么做呢?要知道 ADOQuery是在服务程序中呀,客户程序中没有ADOQuery,只有ClientDataSet控件,这样的话应该怎么写呢?
      

  6.   

    在C端ClientDataSet1.commandtext:='select a1.a a1.b a2.a a2.b from 
    a1 where.....'
    具体的代码明天给你
      

  7.   

    用传统的主从表有点困难 用一种变通的方式:
     在客户端 datasource 的onchange 事件中
    var
    label1:tlabel;
    begin
    label1:=tlabel.creat(form1);
    try
    label1.parent:=form1;
    clientdataset1.open;
    label1.caption:=clientdataset1.filds[0].asstring;
    clientdataset2.close;
    clientdataset2.commandtext:='select*from b where a="'+label1.caption+'"'';
    clientdataset1.open;
    finally
    label1.free;
    end;