Update DBGrid after SQL Insert ??

DelphiRulez
DelphiRulez used Ask the Experts™
on
Delphi 2010 + MS ACCESS 2007 + ADO

I have a dialog form with a TDBGrid on it. I am adding records to a table using SQL insert statements.  How can I update the DBGrid immediately after the SQL Insert call...so the data displays immediately

I have tried -

DBGrid.Invalidate
DBGrid.Repaint
DBGrid.Refreh

table1.Refresh

datasource1.OnStateChange(Self);

etc.

what am i missing?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I ended up just using a TADOTable instead of a TADOQuery.

I will leave this question open. If anyone answers it sucessfully, I will award the points.

Senior developer, analyst and customer assistance
Commented:
I'd call Adoquery1.requery After the insertion.


DisableControls.
Insert your new record by SQL.
Call Adoquery.requery
Locate the inserted value
EnableControls
Top Expert 2010

Commented:
You are missing .... everything ??!

In ADO it is allways better to call:

ADOQuery1.ReQuery;

For the Table it is 'Refresh' ...
I'm afraid this solution did not work for me.  IN fact, none of the ideas in this thread worked.  Neither has a lengthy search of the general net.  I have a similar problem to DelphiRulez.  Maybe it is because I"m dealing with a delete query.  But no matter what I try, I can't get the dbgrid to refresh immediately.  I can do this manually, buy putting a requery into a button on the app, but not when I put the same code in the routine that does the delete.  

disable;
do delete query.
do display requery.
enable;

and the grid sits there with the deleted record gone.  The database is Access.  If I look at it via OO Base at this point, I can see the record is gone.  But it is displayed in the dbgrid anyway, until I hit a button that has an active=false/active=true combination.  My solution is useless except for diagnositcs.  It looks like the code is ok but I can't beat the latency.  Any ideas anyone?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial