Link to home
Start Free TrialLog in
Avatar of andrewjb
andrewjbFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Seeing database changes in a DBGrid


I'm using the ADO components to access an Access database.

I've a TDBGrid pointing to a TDataSource pointing to a TADOTable, giving me a list of what's in that table.

I make a change using a query somewhere else.

How do I get the table to reflect the changes? (In this case an added record, but I'll probably want to delete and modify stuff shortly..)



(Actually using C++Builder, but the database Gurus tend to hang out in this TA!)
ASKER CERTIFIED SOLUTION
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tomas Helgi Johannsson

use    
 ADOTable.Refresh;

after executing the insert/update/delete query

Regards,
  Tomas Helgi
Avatar of andrewjb

ASKER

I'd tried refresh - it doesn't work for some reason.

Requery is great. Anyone know why?
from delphi help :

REQUERY :
Call Requery to refresh the recordset. Requery updates the dataset by re-executing the original command or SQL statement that produced the recordset.

The effects of Requery are the same as calling the dataset’s Close method and then its Open method. However, there are circumstances when one means of refreshing the recordset is better than the other. The values in properties like CursorLocation, CursorType, and LockType cannot be changed while the dataset is open, so Requery can only refresh the recordset using the existing values in these properties. To refresh the recordset using different values for these properties, effect the refresh using the Close and Open methods.

Options is a TExecuteOptions value that specifies the characteristics of the command execution affected by the requery that produces the recordset for the dataset.


REFRESH :
The Refresh method does not work for all TDataSet descendants. In particular, TQuery components do not support the Refresh method if the query is not “live”. To refresh a static TQuery, close and reopen the dataset.



by the way , don't accept this comment as answer please
Regards
Amir
Yup - read that. It's a table, though, not a query. Perhaps just one of Delphi's quirks..