Solved

TQuery results.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

696 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