7

I have a TDBGrid called myDbGrid that I want to update after a change to the database (insert/update/delete). How can I do this without reloading my form completely?

myDbGrid uses myDataSource and it uses myQry as its data set.

I've tried the following with no success:

myDbGrid.Refresh;

and

myDbGrid.DataSource.DataSet.Close;
myQry.Close; // '' I think this is redundant
myQry.Open;
myDbGrid.DataSource.DataSet.Refresh;

What have I missed?

(I'll note that the database change is not happening in the tDBGrid - it's there for display only)

BIBD
  • 15,107
  • 25
  • 85
  • 137
  • Calling just `myDbGrid.DataSource.DataSet.Refresh;` should do that. `myDbGrid.Refresh;` forces the grid to repaint. – TLama Feb 19 '15 at 16:33
  • Maybe the transaction in the database is not being commited? – Guillem Vicens Feb 19 '15 at 16:57
  • 2
    Bone-headed move.... I was refreshing *before* I did my database change and I couldn't see the forest for the trees. I'd close it, but since the next best Google result for my question is from E-E.com I'll leave it open for the next person. If TLama wants to post their comment as an answer, I'll mark it as accepted right away. Thanks for the help. – BIBD Feb 19 '15 at 18:23

3 Answers3

11

The only code that is needed here is:

myDbGrid.DataSource.DataSet.Refresh; 

Everything else is redundant in this particular case.

BIBD
  • 15,107
  • 25
  • 85
  • 137
0

You can try this code:

ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('select* from table_name');
ADOQuery.Open;
Mickael Maison
  • 25,067
  • 7
  • 71
  • 68
0

I'm using ADOQuery, so I did:

ADOQuery1.Active := False;
ADOQuery1.Active := True;