Page 1 of 1

Newbie help needed - SQL query + results

Posted: 26.08.2008, 17:32
by ChaosBiker
As newbie, I already got as far as setting up a connection,
and by means of ZComponent being able to read the databases,
and from a database being able to read all the tables.

Next step woul dbe to perform queries and display results...

Unfortunately could not find how-to's ....

does anyone have an example?

Posted: 27.08.2008, 09:25
by zippo
you can do many things when connected, let's take a simple example:

- Add a TZQuery component into the form and name it (example MyQuery). Link it to the ZConnection component via property Connection.
- Add a TDataSource and link it (property Dataset) to MySQL.
- Add a TDBGrid an connect it to the datasource.
- Enter a SQL sentence into the MyQuery.SQL.Text, ecample "Select * From, TABLENAME.
- In the code execute this MyQuery.Active := true; or MyQuery.Open; In the grid should appear the requested records.

You can do the same in design time to see the result ASAP... ;)

Please note that this is just basic functioning. Upon starting the application you shoud connect and open tables by code - with exception handling.

Posted: 27.08.2008, 21:14
by ChaosBiker
much appreciated,

one thing not quite clear
"Add a TDataSource and link it (property Dataset) to MySQL. "

what do you mean with this?
So I should not use the ZQuery's DataSource to link it to TDataSource?

Posted: 27.08.2008, 21:35
by ChaosBiker
here's what I done so far

add Zconnection
-set Protocol=mssql
-set hostname
-set username
-set password
-set database
add TDataSource
add ZQuery
-set conenction to ZConnection1
-set datasource to TDataSource
-set SQL (query)
add DBGrid
-set datasource to TDataSource

ZConnection.Connect
Zquery1.Open

nada...
found a code somwhere else
memo1.Lines.Add(ZQuery1.FieldByName(ZQuery1.Fields[1].FieldName).asString);

this shows the query is getting a result,
jsut seem to be short the link between ZQuery and TDatasource ???

Posted: 27.08.2008, 22:33
by mdaems
-set datasource to TDataSource
It's the other way round. You should set the Dataset property of your datasource to ZQuery. The datasource property of the ZQuery has something to do with master-detail relationships.

Mark

Posted: 28.08.2008, 06:41
by zippo
TZConnection --> TZQuery.Connection --> TDatasource.Dataset --> TDBGrid.Datasource

Posted: 28.08.2008, 08:25
by ChaosBiker
yay,

works
:)

I was close the first time I experemimented,
but I kept putting TDAtaSource in ZQuery, instead of otherway around :)

Posted: 03.09.2008, 12:11
by zippo
The important thing is that now it's working.. ;)

Posted: 03.09.2008, 20:49
by ChaosBiker
thnx mate