Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TQuery results.

Posted on 2001-08-01
2
Medium Priority
?
239 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 200 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

Independent Software Vendors: 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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