Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display timer during sqlcommand execution like sql server..
Anybody help me to sort out this...
Posted

How about you just start your timer with or before your command execution and end it when you get a result or an exception.

If the application is a GUI app then your code will look like this:
VB
Public Class Form1
    Dim count As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 1000 'Time in miliseconds
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        count += 1
        Label1.Text = count.ToString() & "s"
        If count = 10 Then
            Timer1.Stop()
        End If
    End Sub
End Class


You can put the Timer1.Start()
and the Timer1.Stop()
anywhere you want, and change the tick event to do whatever you want it to do.

So your code should look like this:
VB
Public Class YourClass
'Event that handles the sqlcommand ill go wit the form load
'but whatever you use should be fine
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     Timer1.Start()
     Try ' You should have a try catch for error handling
           'your sqlCommands
     Catch ex as exception
           'Error handling code
     Finally
          Timer1.Stop()
     End Try
End Sub
End Class


Hope it Helps!
 
Share this answer
 
v4
I want timer to be started before sql command execution. After command execution timer need to be stopped...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900