Recent

Author Topic: Adding records to TSQLQuery  (Read 934 times)

LemonParty

  • Full Member
  • ***
  • Posts: 181
Adding records to TSQLQuery
« on: February 15, 2024, 02:10:12 pm »
Hi. I am using TSQLQuery with TDBGrid. When I open Query – everything OK, old records are visible. I am doing the next thing:
Code: Pascal  [Select][+][-]
  1. begin
  2.   Query.Append;
  3.   {edit fields here}
  4.   Query.Post;
  5. end;
  6.  
The code above seems work fine (new records appear in DBGrid). But when I close and open the dataset records added this way disappear. How to make them left?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Adding records to TSQLQuery
« Reply #1 on: February 15, 2024, 02:14:19 pm »
Today is tomorrow's yesterday.

LemonParty

  • Full Member
  • ***
  • Posts: 181
Re: Adding records to TSQLQuery
« Reply #2 on: February 15, 2024, 03:40:59 pm »
Code: Pascal  [Select][+][-]
  1. Query.ApplyUpdates;
Do the thing. Thank you.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Adding records to TSQLQuery
« Reply #3 on: February 15, 2024, 04:44:44 pm »
Thank you for reporting back LemonParty.

Note that I specially mentioned the link in the wiki to get yourself acquainted with transactions as the wiki article explains what a transaction actually does.

Now, that might or might not be applicable to your situation f.e. because you are working with a local database but it definitely comes into play when working with a remote database. You can setup your code so that there is no need to (manually) perform transactions but that is usually an undesirable situation for remote servers.
Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018