Recent

Author Topic: How to easy update changes in DBGrid+SQLQuery?  (Read 10992 times)

vladvons

  • Jr. Member
  • **
  • Posts: 65
How to easy update changes in DBGrid+SQLQuery?
« on: September 07, 2013, 01:23:05 pm »
There is simple Query with DBGRid presentation
SQLQuery1.SQL.Text := ' SELECT * FROM products WHERE products_price = 99'
   
I want automatically to post Grid changes when cursor skips to another record.
Is there somewhere property to make it without writing following code?

Now i use additional bitton with code to save changes:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin 
 SQLQuery1.Edit();
 SQLQuery1.UpdateMode := UpWhereChanged;
 SQLQuery1.ApplyUpdates();
 SQLTransaction1.Commit();
 SQLQuery1.Close();
 SQLQuery1.Open();
                                 

or such another method
Code: [Select]
                                 
procedure TForm1.DBGrid1EditingDone(Sender: TObject);
begin
   SQLQuery1.ApplyUpdates();
end;
         

                   
Windows 7, Ubuntu 12.04, Lazarus 1.2.2, FPC 2.6.4, PostgreSQL 9.2

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: How to easy update changes in DBGrid+SQLQuery?
« Reply #1 on: September 07, 2013, 05:03:39 pm »
In my opinion you must apply updates if you use SQLdb, but try some experiments on event onScroll?!
e.g if Query.State in [dsEdit, dsInsert] then ...
« Last Edit: September 07, 2013, 05:06:36 pm by exdatis »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to easy update changes in DBGrid+SQLQuery?
« Reply #2 on: September 07, 2013, 05:08:50 pm »
Personally I would use the SQLQuery AfterPost event to call ApplyUpdates everything else is a bit long winded for my liking.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018