Solved

TQuery results.

Posted on 2001-08-01
2
236 Views
Last Modified: 2010-04-06
Hi.

I've got an application I'm working on and I need to do the following...

 function GetCustomerName(sAccNum: String): String;
 begin
   with TQuery.Create(nil) do begin
     DatabaseName:='RelevantAliasName';
     SQL.Add('Select CustomerName from CustomerDetails where AccountNumber='''+sAccNum+'''');
     ExecSQL;
     Result:=??????????;
     free;
   end;
 end;

so that I can simply do something like....

  ShowMessage(GetCustomerName('1234'));

The problem I have is the results line.  Can someone tell me how to reference the results that I glean in this manner?  (I've tried referencing the TFields property, Fields, but there appears to be nothing in it.)

Thanks,

John.
0
Comment
Question by:Jaymol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 6340035
try

result := fieldByName('CustomerName').AsString;
or
result := fields[0].AsString;

better do a test before like

if not IsEmpty then
  result := fieldByName('CustomerName').AsString;
else
  result := '';

if this not solves this, then use a var instead of with ... do

oh, and just use open instead of execsql or SQL.Exec

meikl ;-)
0
 
LVL 6

Author Comment

by:Jaymol
ID: 6340050
Thanks Meikl.

Quite annoying that I'd already tried that and it hadn't worked!  (Only difference was the check IsEmpty.)

Thanks again,

John.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question