Windows应用程序vb.net中执行sql命令的计时器 [英] timer for sql command execution in windows application vb.net

查看:117
本文介绍了Windows应用程序vb.net中执行sql命令的计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在像sql server这样的sqlcommand执行期间显示计时器..
任何人都可以帮助我解决这个问题...

I want to display timer during sqlcommand execution like sql server..
Anybody help me to sort out this...

推荐答案

您如何在命令执行之前或之前启动计时器,并在得到结果或结果时结束计时器呢?例外.

如果该应用程序是GUI应用程序,那么您的代码将如下所示:
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:
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



您可以将Timer1.Start()
Timer1.Stop()
您想要的任何位置,然后更改tick事件以执行您想执行的任何操作.

因此您的代码应如下所示:



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:

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!


我希望在执行sql命令之前启动计时器.在命令执行计时器需要停止之后...
I want timer to be started before sql command execution. After command execution timer need to be stopped...


这篇关于Windows应用程序vb.net中执行sql命令的计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆