Hej,
I need some basic help with the interaction of the visual DB components, maybe a hint for what to reread.
Situation:
I want to display data in a DBGrid. When selected I want to display dependent information in a second DBGrid. It is 1:n, e.g. a user and a list of associated notes (by a foreign key in the notes table). I use SQLite. The basic part works due to the nice tutorials in the wiki.
Idea:
SQLiteConnection, SQLTransaction, SqlQuery1, DataSource1 for DBGrid1. Event OnDataChange in DataSource1 fires; then I execute SqlQuery2 for DataSource2 for DBGrid2 for the dependent data. Of course no second connection or transaction is used.
Problem:
The event is called but the dependent data is loaded only once (at first call). The data for the first call is displayed correctly in the DBGrid2 but no changes are shown for subsequent calls.
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
SqlNotiz.Sql.Text:='select * from notes n where n.id_user = :user';
SqlNotiz.Params.ParamByName('user').AsInteger:=DataSource1.DataSet.Fields[0].AsInteger;
SqlNotiz.Open;
Label1.Caption:='Changed to '+DataSource1.DataSet.Fields[0].AsString;
end;
It's obvious that I miss something basic like refreshing the sql statement or properly closing it. I would be thankful for any hints (also about hints how to do it differently if the whole approach is done in other ways normally or better).