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.

hawkerpacAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jimyXCommented:
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

0
jimyXCommented:
Or simply you can assign the value AsString:
...
  cop_qryactstd.Close;
  cop_qryactstd.Parameters.ParamValues['nbr1'] :=  cop_edtfwo1.Text;
  cop_qryactstd.Parameters.ParamValues['nbr2'] :=  cop_edttwo1.Text;
  cop_qryactstd.Open;
  Edit1.Text := cop_qryactstd.FieldByName('ActHrs').AsString;
...

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimyXCommented:
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

0
hawkerpacAuthor Commented:
Thanks for the help. Worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.