Recent

Author Topic: sqlite and zeos  (Read 3439 times)

addr3ss

  • New Member
  • *
  • Posts: 18
sqlite and zeos
« 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

Danyfirex

  • New Member
  • *
  • Posts: 13
Re: sqlite and zeos
« Reply #1 on: July 01, 2015, 07:49:24 pm »
hi. maybe you must explain better. I think you can use update instead of select.

Saludos

addr3ss

  • New Member
  • *
  • Posts: 18
Re: sqlite and zeos
« Reply #2 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.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: sqlite and zeos
« Reply #3 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

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: sqlite and zeos
« Reply #4 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

Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

addr3ss

  • New Member
  • *
  • Posts: 18
Re: sqlite and zeos
« Reply #5 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