Newbie help needed - SQL query + results

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
ChaosBiker
Fresh Boarder
Fresh Boarder
Posts: 22
Joined: 26.08.2008, 12:36

Newbie help needed - SQL query + results

Post 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?
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post 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.
ChaosBiker
Fresh Boarder
Fresh Boarder
Posts: 22
Joined: 26.08.2008, 12:36

Post 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?
ChaosBiker
Fresh Boarder
Fresh Boarder
Posts: 22
Joined: 26.08.2008, 12:36

Post 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 ???
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

TZConnection --> TZQuery.Connection --> TDatasource.Dataset --> TDBGrid.Datasource
ChaosBiker
Fresh Boarder
Fresh Boarder
Posts: 22
Joined: 26.08.2008, 12:36

Post by ChaosBiker »

yay,

works
:)

I was close the first time I experemimented,
but I kept putting TDAtaSource in ZQuery, instead of otherway around :)
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

The important thing is that now it's working.. ;)
ChaosBiker
Fresh Boarder
Fresh Boarder
Posts: 22
Joined: 26.08.2008, 12:36

Post by ChaosBiker »

thnx mate
Post Reply