0

我如何使用 2 个 Tadoquery 并像 Tadoquery(主)Tadotable(详细)一样工作!

    var  tempvar : Variant;             
    begin  
    Edit1.text:=Ano.value;
    Begin  
      with Ano_planeamento do //Laço de consulta por codigo  
       Begin  
        Close;    
        SQL.Clear;  
        SQL.Add('SELECT * from planeamento_ano');  
        SQL.Add('Where ano LIKE ''%'+Edit1.text+'%''');  
        Open; 
        end; 
     end; 
     tempvar := Ano_planeamento.fieldbyname('ano').value;  
     planeamento.close;  
     if tempvar <> null then 
     begin  
      planeamento.SQL.Clear; 
      planeamento.SQL.add('SELECT * FROM planeamento');  
      planeamento.SQL.add(' WHERE ano = ');  
      planeamento.SQL.add('''' + tempvar + '''');   
       // here i nead to filter by ....        
      planeamento.open;
4

2 回答 2

2

If in the detail you set the datasource to the master then you can try using parameters in the detial that match a field in the master. So if in the master you have the following: SELECT field1, field2, field3 FROM table Then in the detail you have: SELECT d_field1, d_field2, d_field3 FROM detail WHERE some_field=:field1 So that the parameter 'field1' has the same name of a field (field1) returned from the master.

于 2010-05-30T01:10:22.677 回答
0

从古代历史来看(即五年前),使用 VCL 数据集自动处理主/详细信息的方式是通过在关联的 TDatasource 组件上设置属性。见这里的例子: http ://delphi.about.com/library/howto/htdbmasterdetail.htm

否则,只需为详细数据集动态更改 SQL 中的 WHERE 子句,或在详细数据集上设置 Filter 属性:http: //docwiki.embarcadero.com/VCL/en/DB.TDataSet.Filter

于 2010-05-29T20:20:11.387 回答