Forum > Databases

TDBGrid: how to edit data

(1/1)

jshand2010:
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.

teos:
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:
Hi! Maybe you need to define more connections...

This is an example for Sqlite3...

--- Code: ---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;

--- End code ---

Russell:
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

Navigation

[0] Message Index

Go to full version