Solved

TQuery results.

Posted on 2001-08-01
2
231 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now