如何通过计时器控件将SQL日期和时间转换为标签 [英] How can I get SQL Date and time into label with timer control

查看:116
本文介绍了如何通过计时器控件将SQL日期和时间转换为标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我解决这个问题..我想在我的表单上显示服务器时间并使用计时器运行它...我不想显示本地日期时间



please help me about this .. i want to show server time into lable on my form and run it with timer.. i dont want to show the local datetime

Imports System.Data.SqlClient
Public Class frm_secure_mornning
       Dim current_datetime As DateTime
    Private Sub frm_secure_mornning_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


     Timer1.Interval = 1000
        Timer1.Enabled = True    End Sub

          Cn.Open()
       
        Dim cmd As New SqlCommand("select GetDate();", Cn)
        current_datetime = cmd.ExecuteScalar
        Cn.Close()
    End Sub

      
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
               lblDatetime.Text = current_datetime
    End Sub
End Class

推荐答案

我会创建一个SQL存储过程,称之为server_time。该过程将SELECT GETDATE()简单地作为[dateandtimecolumn]

然后我将该过程导入vb,调暗适配器和表,并填充表。获取日期和时间:var as dateAndTime = table(0).columns(0).value



当然,数据可能会被秒钟关闭,这很多通过网络的流量。我可以建议一次调用此程序来查找服务器和本地计算机之间的区别,以便可以在当地时间加/减吗?
I would create an SQL stored procedure, calling it server_time. The procedure would simply SELECT GETDATE() as [dateandtimecolumn]
Then I would import the procedure into vb, dim an adapter and table, and fill the table. Get the date and time : var as dateAndTime = table(0).columns(0).value

Of course the data could be off by seconds and that's a lot of traffic over a network. may I suggest calling this procedure one time to find the difference between your server and local machine so that you can add/subtract to or from your local time?


这篇关于如何通过计时器控件将SQL日期和时间转换为标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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