Link to home
Start Free TrialLog in
Avatar of hawkerpac
hawkerpac

asked on

How to get a value from TADOQuery and assign to a text field.

I have a query in the TADOQuery
select sum(wr_run) as ActHrs from pub.wr_route where "wr_nbr" >= :nbr1
                                                                                    and wr_nbr <= :nbr2

Run time i want to assing the value Acthrs to a text field.

I have done the following

    cop_qryactstd.Close;
    cop_qryactstd.Parameters.ParamValues['nbr1'] :=  cop_edtfwo1.Text;
    cop_qryactstd.Parameters.ParamValues['nbr2'] :=  cop_edttwo1.Text;
    cop_qryactstd.Open;

   Now how to assign the value to the text field.

  Thanks in advace for the help.

Avatar of jimyX
jimyX

Since there are numbers involved Sum returns Float. Then what you can do is to get the value as Float and convert to String.
...
  cop_qryactstd.Close;
  cop_qryactstd.Parameters.ParamValues['nbr1'] :=  cop_edtfwo1.Text;
  cop_qryactstd.Parameters.ParamValues['nbr2'] :=  cop_edttwo1.Text;
  cop_qryactstd.Open;
  Edit1.Text := FloatToStr(cop_qryactstd.FieldByName('ActHrs').AsFloat);
...

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jimyX
jimyX

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
Also you can format the returned figure for arithmetic precision:
...
  cop_qryactstd.Close;
  cop_qryactstd.Parameters.ParamValues['nbr1'] :=  cop_edtfwo1.Text;
  cop_qryactstd.Parameters.ParamValues['nbr2'] :=  cop_edttwo1.Text;
  cop_qryactstd.Open;
  Edit1.Text := Format('%0.2n', [cop_qryactstd.FieldByName('ActHrs').AsFloat]);  // for 2 decimal places
...

Open in new window

Avatar of hawkerpac

ASKER

Thanks for the help. Worked.