Refresh database automatically

Posted on 2006-03-31
Medium Priority
Last Modified: 2010-04-05

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.

Question by:Stef Merlijn
LVL 15

Expert Comment

ID: 16349611
Surely the only way would be to close and reopen the query to the table to specifically call a refresh or am I wrong?

Expert Comment

ID: 16358440
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);
    Application.OnActivate := AppOnActivate;

procedure TForm1.AppOnActivate(Sender: TObject);

with regards,

Author Comment

by:Stef Merlijn
ID: 16358471
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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

by:Stef Merlijn
ID: 16358487
By the way I use a TMySQLTable that has property Refresh.
LVL 11

Expert Comment

ID: 16360332
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,

Author Comment

by:Stef Merlijn
ID: 16360361
pcsentinel: Could you give an example for that?
LVL 11

Accepted Solution

pcsentinel earned 2000 total points
ID: 16360495
say your table has

ID > int AutoID
Name > clientname
Address > address
LastUpdate > int > field that is incremented everytime the record is edited

right a stored proc that

sums the ID+LastUpdate field for all records

sorry dont know MySQL so not sure of Syntax, but for SQL Server would be something like

@Checksum int OUTPUT
  SET @Checksum=(SELECT SUM(ID + LastUpdate) FROM MyTable)

when they first open the table run the query to get your staring checksum

then on a timer say every 5 secs, run the GetCheckSum procedure and if its different then you know you need to refresh the display, check that the user is in dsBrowse mode, if not then you dont need to worry because they will refresh the data after the edit.

Author Comment

by:Stef Merlijn
ID: 16361147
That is very nice suggestion.
I've tested it and it works just fine.
Thank you.

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month15 days, 13 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question