I have a datamodule with a IBConnection component, a SQLQuery component, a SQLTransaction component, and a Datasource component on it.
I have a form with some TEdits, a TDBCombobox and a DBGrid and a button to save new records with. FYI, I only used two of the fields to just do testing and to learn on for now. Here is the code under the Save button:
procedure TfrmMain.btnCommitClick(Sender: TObject);
begin
with DataModule1.SQLQry_TimeSheets do
begin
Insert;
FieldByName('pid').AsInteger := 10;
FieldByName('client').AsString := DBcboClients.Text;
Post;
ApplyUpdates;
DataModule1.SQLTrans_TimeSheets.Commit;
DBGrid1.Refresh;
//Close;
//Open;
end;
end;
I have several questions regarding my code:
1) Is the "Post" needed?
2) Just using DBGrid1.ReFresh does not cause the DBGrid to show the new record. However, eliminating the DBGrid1.ReFresh and enabling the "Close" and "Open" do cause the DBGrid to show the new record. Even thought this works, is this the proper way to code this?
3)Finally, are there more proper ways to do all of this? I know I could use TDBEdits but I have my reason for just using TEdits.
Just trying to learn to code properly ....
Thanks,
TD