Lazarus

Programming => Databases => Topic started by: addr3ss on June 30, 2015, 01:19:34 pm

Title: sqlite and zeos
Post by: addr3ss on June 30, 2015, 01:19:34 pm
Hello!
I want to excute a select query and replace the result with a label caption.I very searched but I did not find a clear way.Can anyone explain it step by step?tnx
Title: Re: sqlite and zeos
Post by: Danyfirex on July 01, 2015, 07:49:24 pm
hi. maybe you must explain better. I think you can use update instead of select.

Saludos
Title: Re: sqlite and zeos
Post by: addr3ss on July 02, 2015, 10:46:12 am
No I want to select some data from DB.I added a Zconnection and setted library and db type and database fields.then added a Zquery and setted my query and connection.but i dont know how to assign query result to a label caption.
Title: Re: sqlite and zeos
Post by: rvk on July 02, 2015, 11:12:09 am
If your Zconnection and Zquery are set correctly you can do something like this:

Code: [Select]
  ZConnection1.Connect; // if your ZConnection is not connected yet
  ZQuery1.Open;         // if your ZQuery with the select isn't open yet

  // this will get the value from field 'your_desired_field' from the first record
  Label1.Caption := ZQuery1.FieldByName('your_desired_field').asString;

  // if you have multiple records
  ZQuery1.Next;

  // this will get the value from field 'your_desired_field' from the second record
  Label1.Caption := ZQuery1.FieldByName('your_desired_field').asString;


This wiki is for SqlDB but it's almost the same for Zeos (especially for reading from a dataset):
http://wiki.freepascal.org/SqlDBHowto#How_to_read_data_from_a_table.3F
Title: Re: sqlite and zeos
Post by: jma_sp on July 02, 2015, 11:48:25 am
Thanks rvk. :)

addr3ss you can also use TDBTEXT in the data controls tab. If connection is OK and also Query Ok it must show some data. You can use tdbnavigator to move across records, equivalent to the explanation of rvk but more friendly visualy.

zquery1.next
zquery1.prev

The advantage of the response of rvk is that you can assign the code directly at your own button for specific functions.

More information about this components:

http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbnavigator.html
http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/howtousedataawarecontrols.html

Title: Re: sqlite and zeos
Post by: addr3ss on July 03, 2015, 12:19:40 pm
If your Zconnection and Zquery are set correctly you can do something like this:

Code: [Select]
  ZConnection1.Connect; // if your ZConnection is not connected yet
  ZQuery1.Open;         // if your ZQuery with the select isn't open yet

  // this will get the value from field 'your_desired_field' from the first record
  Label1.Caption := ZQuery1.FieldByName('your_desired_field').asString;

  // if you have multiple records
  ZQuery1.Next;

  // this will get the value from field 'your_desired_field' from the second record
  Label1.Caption := ZQuery1.FieldByName('your_desired_field').asString;


This wiki is for SqlDB but it's almost the same for Zeos (especially for reading from a dataset):
http://wiki.freepascal.org/SqlDBHowto#How_to_read_data_from_a_table.3F

tnx worked.
TinyPortal © 2005-2018