Link to home
Start Free TrialLog in
Avatar of Paul Brooks
Paul BrooksFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Populating data grid

Morning all
I need to populate a data grid using 2 criteria. The code i am trying is giving me a few problems as i am trying to set the SQL query for the first criteria and the filter for the second. The filter is working fine but i am having trouble with the SQL. There must be a more elegant way of doing this. My code so far is

procedure TFrmsalessearch.Button1Click(Sender: TObject);
var
accno : string;

begin
        Application.createform(Tfrmcontsearch, frmcontsearch);
          accno :=cmbsalesacc.text;
          frmcontsearch.Sqlcontracts.Active:=false;
          frmcontsearch.Sqlcontracts.SQL.Clear;
          frmcontsearch.Sqlcontracts.SQL.add('select * from CONTRACT_INFO where CLIENT_CODE = '+cmbsalesacc.text);
          frmcontsearch.Sqlcontracts.Active:=true;
          frmcontsearch.SQLcontracts.Filter:='CONTRACT_COMPLETE=' + QuotedStr('N');
          frmcontsearch.SQLcontracts.Filtered:=true;
          Frmcontsearch.label1.Caption := accno;
          frmcontsearch.showmodal;

end;

Any ideas are most welcome

Best regards
ASKER CERTIFIED SOLUTION
Avatar of RadikalQ3
RadikalQ3
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or... if your sql engine doesn need the quotes, like in the first condition if the where:

'where CLIENT_CODE = '+cmbsalesacc.text

maybe the quotedstr is not needed (depends of the sql engine used):

  frmcontsearch.Sqlcontracts.SQL.add( 'select * from CONTRACT_INFO '+
                                      'where CLIENT_CODE = '+cmbsalesacc.text+
                                      ' and CONTRACT_COMPLETE=N');