Recent

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

LemonParty

  • Jr. Member
  • **
  • Posts: 98
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?

TRon

  • Hero Member
  • *****
  • Posts: 3747
Re: Adding records to TSQLQuery
« Reply #1 on: February 15, 2024, 02:14:19 pm »
I do not have to remember anything anymore thanks to total-recall.

LemonParty

  • Jr. Member
  • **
  • Posts: 98
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.

TRon

  • Hero Member
  • *****
  • Posts: 3747
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.
I do not have to remember anything anymore thanks to total-recall.

 

TinyPortal © 2005-2018