Recent

Author Topic: TDBGrid: how to edit data  (Read 5395 times)

jshand2010

  • Full Member
  • ***
  • Posts: 236
TDBGrid: how to edit data
« on: March 05, 2013, 10:56:23 am »
what settings must you have right before the grid will show and enable you to edit the information.

TPQConnection:

i have set it up to connect to a database with the right username nad password and connects without a problem.

TSQLQuery:

i have connected to TPQConnection, left Datasource blank.  transaction is correctly chosen.  in sql i have selected all from the product table.  set active to true

TSQLTransaction:

This is pretty straight forward.

TDatasource:

i have connected the datasource to the TSQLQuery.

DBGrid:

i have set the datasource to the datasource.  set all titles to corresponding fields and connected all the fields.
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

teos

  • Full Member
  • ***
  • Posts: 161
Re: TDBGrid: how to edit data
« Reply #1 on: April 06, 2013, 03:49:07 pm »
If you set TSQLQuery active and it supports editing, the DBGrid will show editable data. From the properties, I suppose you need to enter SQL in the insertsql and updatesql properties.

I'm sure someone can improve my answer but maybe it's a pointer in the right direction.

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: TDBGrid: how to edit data
« Reply #2 on: April 06, 2013, 05:54:38 pm »
Hi! Maybe you need to define more connections...

This is an example for Sqlite3...
Code: [Select]
procedure TfrmSeeBook.ButtonShowMeBooks_OnClick(Sender: TObject);
begin   
  Sqlite3Dataset1.FileName := 'sqlite3.db';
  Sqlite3Dataset1.TableName := 'books';
  Sqlite3Dataset1.PrimaryKey := 'book_id';
  DataSource1.DataSet := Sqlite3Dataset;
  Sqlite3Dataset1.SQL :=  'SELECT * FROM books WHERE active="1" ORDER BY book_id';

  DBGrid1.DataSource := DataSource1;
  DBNavigator1.DataSource := DataSource1;
  Sqlite3Dataset1.ExecSQL;
  Sqlite3Dataset1.Open;

  Sqlite3Dataset1.Active := True;
  Sqlite3Dataset1.SaveOnClose := True;
  Sqlite3Dataset1.SaveOnRefetch := True;
end;

Russell

  • Newbie
  • Posts: 3
Re: TDBGrid: how to edit data
« Reply #3 on: July 04, 2024, 05:13:27 am »
Under lazarus the TSQLQuery has 5 options (in my version - 2.2.0 on windows 64)
When I set sqoAutoApplyUpdates, sqoAutoCommit and sqoKeepOpenOnCommit each to true, the TDBGrid started saving my data. Otherwise, I had everything as stated in the original question.

Russell

 

TinyPortal © 2005-2018