(solved) basic question-Tzquery lazarus / 16-Databases ---------------------------------------------------------------------- aliboy · 2012-11-24 13:11 hi dear i read this tutorial and  have a basic question about writing query. http://wiki.freepascal.org/Zeos_tutorial QuoteDrop a ZConnection. Set your User, Password, Host, Port and Protocol (and any other params if needed). Set Connected to True. Drop a ZQuery (do not mistake with ZReadOnlyQuery). Set the Connection to your active ZConnection. Set the Sql property to something like SELECT * FROM MyTable Set Active to True. Drop a DataSource from the [Data Access] tab. Set the DataSet to your active ZQuery. Drop a DBGrid from the [Data Controls] tab. Set the Datasource to your DataSource. If all is ok you should now be able to see the records from your table  (notice: I used  ZConnection1,ZQuery1,Datasource1,DBGrid1  and can make connection to database ) and i added this code to FormCreate  (onCreate event) to show data in DBgrid. Code: [Select]ZQuery1.SQL.Clear;   ZQuery1.SQL.Add('select * from tlb');   ZQuery1.ExecSQL; my problem occurs when goning to ENABLE ZQuery but facing with this error: Quote SQL Query is empty I would like to get data from database with write query (not change  SQL property of ZQuery1). is there need other object such as ZUpdateSQL1? thanks a lot. ---------------------------------------------------------------------- vfclists · 2012-11-24 14:37 Shouldn't it be ZQuery1.Open rather than ZQuery1.ExecSQL? ---------------------------------------------------------------------- aliboy · 2012-11-24 15:38 Quote from: vfclists on November 24, 2012, 03:37:34 pmShouldn't it be ZQuery1.Open rather than ZQuery1.ExecSQL? when i used ZQuery1.ExecSQL project loaded with no error and Dbgrid had no data, Code: [Select]ZQuery1.SQL.Clear;   ZQuery1.SQL.Add('select * from tlb');   ZQuery1.ExecSQL  and when used ZQuery1.Open  had a memory error. Code: [Select]ZQuery1.SQL.Clear;   ZQuery1.SQL.Add('select * from tlb');   ZQuery1.open i think connecting to database has a tip that i search for it. actually i have 2 problems 1-SQL Query is empty   2-i would like to write query to get data on   FormCreate ---------------------------------------------------------------------- EgonHugeist · 2012-11-24 17:42 You are posting everywhere around and nobody knows if your threads are solved or not.  TZQuery.Open; opens a resultset and fetches the data from the database. TZQuery.ExecSQL; simply executes a statement but no resultset is retrived. Only an updatecount is validated. What is a memory-error? Give all peoples more details to help you getting in. Also read the tutorials. ---------------------------------------------------------------------- aliboy · 2012-11-24 22:10 Ok.thanks. I install Lazarus 1.0.2 . I create a form (form1) and drag these objects to it and for each component change  some properties: 1-Zconnection1 clientcodepage=utf8 conncted:ture database:amahi libararylocation:G:\programming\Lazrus_P\DataBase\Example2\libmysql.dl l port:3306 user:root password: protocol:mysql-5 (amahi is my database name at mysql) (my username has no password so it is blank) 2-ZQuery1 connection:ZConnection1 (in default   Active:false i didn't change it ) 3-datasource1 dataset:ZQuery1 4-dbgrid1 Datasource:Datasource1 5-form1 onCreate:  ZQuery1.SQL.Clear;   ZQuery1.SQL.Add('select * from tlb');   ZQuery1.ExecSQL; with this changes, the project ran but dbgrid couldn't show data. so for ZQuery1  change Active to true and Lazarus says: Sql query is empty. for avoiding this error must add a sql command to SQL property of ZQuery1.(for example: select * from tlb) ==>and dbgrid shows data I would like to get data from database with write query (not change  SQL property of ZQuery1). OK? thank you. ---------------------------------------------------------------------- aliboy · 2012-11-28 21:32 it solved: onCreate form must add this code:   Code: [Select]ZQuery1.SQL.Clear;   ZQuery1.SQL.Add('select * from s');   ZQuery1.Open;   ZQuery1.Active:=true; ---------------------------------------------------------------------- BigChimp · 2012-11-29 10:33 Glad you got it solved and thanks for posting. If you think you can update the tutorial so others can benefit, please be my guest. Don't worry too much about the English or formatting as others can always fix that - it is much more difficult to write content than to correct some spelling errors. A tiny hint: rather than using the Insert Quote button around your code on your posts, try the Insert Code button next to it (that looks like #)