Stef Merlijn
asked on
Refresh database automatically
Hi,
I would like to update (refresh) a MS-SQL table let's say every minute. So any new records or changes are presented to me.
Of course refreshing should only be executed when the table is in dsBrowse mode.
Refreshing has only to occur when a certain form is opened.
So user opens the form containing the grid of the MS-SQL table.
Can anybody give me an example on how to implement this? Please keep it as simple as possible.
Regards,
Stef
I would like to update (refresh) a MS-SQL table let's say every minute. So any new records or changes are presented to me.
Of course refreshing should only be executed when the table is in dsBrowse mode.
Refreshing has only to occur when a certain form is opened.
So user opens the form containing the grid of the MS-SQL table.
Can anybody give me an example on how to implement this? Please keep it as simple as possible.
Regards,
Stef
Surely the only way would be to close and reopen the query to the table to specifically call a refresh or am I wrong?
Hello Sir,
To refresh the only way is to Close and Open the Query as mikelittlewood says. If this should happen when you open the form you could do it on FormActivate, but this will not be called when you move from one application to another application, but calls when you move from one form to another form, if you wish to do this refreshing when you move from one application to another application, then here is the code to do it.
procedure AppOnActivate(Sender: TObject);
//declare the above procedure definition in the private section of Form1.
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnActivate := AppOnActivate;
end;
procedure TForm1.AppOnActivate(Sende r: TObject);
begin
Query1.Close;
Query1.Open;
end;
with regards,
padmaja.
To refresh the only way is to Close and Open the Query as mikelittlewood says. If this should happen when you open the form you could do it on FormActivate, but this will not be called when you move from one application to another application, but calls when you move from one form to another form, if you wish to do this refreshing when you move from one application to another application, then here is the code to do it.
procedure AppOnActivate(Sender: TObject);
//declare the above procedure definition in the private section of Form1.
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnActivate := AppOnActivate;
end;
procedure TForm1.AppOnActivate(Sende
begin
Query1.Close;
Query1.Open;
end;
with regards,
padmaja.
ASKER
The problem isn't so much refreshing the table, but how to do it automatically.
Maybe a thread can be used or a timer, but I don't know how to implement it in such a way that it won't interfere with changes made by the enduser.
There is no other application that needs access to the database.
Maybe a thread can be used or a timer, but I don't know how to implement it in such a way that it won't interfere with changes made by the enduser.
There is no other application that needs access to the database.
ASKER
By the way I use a TMySQLTable that has property Refresh.
Another approach is to use a timer that runs a stored procedure that returns some sort of checksum on the table, if that value has changed then refresh the data else don't bother,
ASKER
pcsentinel: Could you give an example for that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is very nice suggestion.
I've tested it and it works just fine.
Thank you.
I've tested it and it works just fine.
Thank you.