views:

99

answers:

2

How can i work with 2 Tadoquery and work like a Tadoquery (master) Tadotable(detail) !!

    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;
A: 

Speaking from ancient history (i.e, over five years ago) the way master/detail was handled automatically with VCL datasets was by setting properties on associated TDatasource components. See here for an example: http://delphi.about.com/library/howto/htdbmasterdetail.htm

Otherwise just dynamically alter the WHERE clause in the SQL for the detail dataset, or set the Filter property on the detail dataset: http://docwiki.embarcadero.com/VCL/en/DB.TDataSet.Filter

Herbert Sitz
+2  A: 

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.

yozey