How to get a single value from MySQL(executescalar in .NET)?

Forum related to version 6.1.5 of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
sheridan101
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 14.10.2010, 16:14

How to get a single value from MySQL(executescalar in .NET)?

Post by sheridan101 »

Hi all.

Although I have extensive programming experience I am new to Delphi (ver. 7) and Zeos.
More or less I was able to figure out how to use Zeos objects and how to link them to controls etc.

What I was unable to figure is how to use command in SQL language to find and get single value from some table.
For example.
I want to use SQL command:

Code: Select all

SELECT UserID FROM Users WHERE FirstName = 'John'
and to get single integer value.
Up to now I executing SQL commands trough ZSQLProcessor and this works fine but there is no returning value.

I hope the questions is not too stupid :cry:

Thanks in advance.
guidoaerts
Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Post by guidoaerts »

Put a TZQuery on your form, fill in the zconnection and the sql and open it.
If you add a TDatasource and TDBGrid, you see the result in designtime.
guido
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

sheridan101,
You have some options.
The most efficient is using the dbc layes directly, as is done in examples/dbc. However this is a little bit too 'specialised'.
The simplest way is dropping a TZConnection and a TZQuery on your form. Open the connection and the query and then read the first field of the current record.
Basically (but NOT tested):

Code: Select all

ZQuery1.sql.text := <your query>;
ZQuery1.Connection := Connection1;
ZQuery1.open;
l_result := ZQuery1.Fields[0].AsString;
Mark
Image
Post Reply