Link to home
Start Free TrialLog in
Avatar of ST3VO
ST3VOFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Query assistance needed - Populate var with Query result

Hi experts,

I'm a bit stuck here.

I want to look for a the company name of an accountID

So I thought I'd do a query.

See code:

The problem is that I wanted to assign the result to a variable (opened to suggestions here).

So, I can then assign the result to a Label.caption.

I really don't know how to do this.

Could someone help please?

Thanks

ST3VO

Try
       CompName:=(memo2.Text);
       adoquery1.active := false;
       adoquery1.SQL.Add('select CompanyName from motors where AccountID = "' +(CompName)+'"');
       adoquery1.Active := true;
 
      finally
        CompName:= ADOQuery1;
        Label1.Caption:=('CompName');
        ADOQuery1.active := false;
        ADOQuery1.Close;
        ADOQuery1.SQL.Clear;
      end;
       end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America 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
Continuing from ciuly's answer, if you want to still store the result in your CompName variable, you'd obviously do this:
CompName := adoquery1.fieldbyname('CompanyName').asString;
Avatar of ST3VO

ASKER

Perfect thanks!!!