hi..is it possible to run SQL query periodically in vb.net?

my system should update database B if there is an anamolly happen in database A
i just wanna run UPDATE query periodically every 5-10 minutes

plz help me

hi zarulhamdi,

the simplest way to do something periodically is to use a timer - drag a timer from the toolbox onto your form. Set the interval and enable the timer either in the property window or in code like this:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Timer1.Interval = 600000
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If FindAnomalies() = True Then
        End If
    End Sub

Every 600000 milliseconds (10 minutes), the Tick event will fire and you can do your checking and/or updating.

One drawback of doing things this way is that, if the checking and updating takes a fair bit of work, it will interfere with the smooth running of your program. This is because the timer runs in the same thread as the form. The only way to get around this is to do this work on another thread. If you're not too familliar with working with threads, it might be better to avoid this as things can get very complicated very quickly. If you want to explore this further, you can drag a BackgroundWorker onto your form and get it to do the work every time your timer ticks, but only do this if it absolutely essential and you are prepared to do a lot more work. Good luck.

This question has already been answered. Start a new discussion instead.