• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 816
  • Last Modified:

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.

0
hawkerpac
Asked:
hawkerpac
  • 3
1 Solution
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now