Click here to Skip to main content
15,908,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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
Posted
Updated 2-Aug-13 10:00am
v2
Comments
Dave Kreskowiak 2-Aug-13 16:13pm    
You're code block is either really messed up when you pasted it or your code makes no sense at all and won't even compile.
Idle_Force 2-Aug-13 22:54pm    
Wouldn't a Web Service be a better option? I mean I want to know too. I know it can be done both ways.

1 solution

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?
 
Share this answer
 
v3

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