BIBD
BIBD

Reputation: 15414

How do I refresh a TDBGrid?

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)

Upvotes: 7

Views: 17923

Answers (3)

I'm using ADOQuery, so I did:

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

Upvotes: 0

Eko Salvinus
Eko Salvinus

Reputation: 1

You can try this code:

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

Upvotes: 0

BIBD
BIBD

Reputation: 15414

The only code that is needed here is:

myDbGrid.DataSource.DataSet.Refresh; 

Everything else is redundant in this particular case.

Upvotes: 12

Related Questions