7
votes

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)

3
Calling just myDbGrid.DataSource.DataSet.Refresh; should do that. myDbGrid.Refresh; forces the grid to repaint. - TLama
Maybe the transaction in the database is not being commited? - Guillem Vicens
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

3 Answers

10
votes

The only code that is needed here is:

myDbGrid.DataSource.DataSet.Refresh; 

Everything else is redundant in this particular case.

0
votes

You can try this code:

ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('select* from table_name');
ADOQuery.Open;
0
votes

I'm using ADOQuery, so I did:

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