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

Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 14.10.2010, 16:14

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

Postby sheridan101 » 14.10.2010, 16:34

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.

Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Postby guidoaerts » 19.10.2010, 18:38

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.

User avatar
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium

Postby mdaems » 08.11.2010, 01:45

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;;
l_result := ZQuery1.Fields[0].AsString;


Return to “6.1.5”

Who is online

Users browsing this forum: No registered users and 1 guest