How to Update or Insert Date Values Into SQL Database

Respons: 0 comments

How to Update or Insert Date Values Into SQL Database

To Insert /Update Date into SQL Server , Use the following method

LogoutTime=CONVERT(datetime,'" & Now.ToString("yyyy-MM-dd HH:mm:ss") & "',101)

Here is another method to update or insert with Parameters Query

 Public MAINCON As New SqlClient.SqlConnection  
  Dim SqlStr As String = ""  
     SqlStr = "INSERT INTO [UserLogFile]([UserName],[LoginTime],[LogoutTime],[LiveTime],[SystemName],[LoginTimeValue],[Transcode])" _  
       & " VALUES (@UserName,@LoginTime,@LogoutTime,@LiveTime,@SystemName,@LoginTimeValue,@Transcode)"  
     MAINCON.ConnectionString = ConnectionStrinG  
       Dim DBF1 As New SqlClient.SqlCommand(SqlStr, MAINCON)  
       With DBF1.Parameters  
         .AddWithValue("UserName", CurrentUserName)  
         .AddWithValue("LoginTime", Now.ToString("yyyy-MM-dd HH:mm:ss"))  
         .AddWithValue("LogoutTime", Now.ToString("yyyy-MM-dd HH:mm:ss"))  
         .AddWithValue("LiveTime", 0)  
         .AddWithValue("SystemName", System.Environment.MachineName)  
         .AddWithValue("LoginTimeValue", Now.Date.ToOADate)  
         .AddWithValue("Transcode", UserLogInlogoutID)  
       End With  
     Catch ex As Exception  
     End Try  

From the Previous Post, Execute Query is very easy to UPDATE INSERT DELETE .


 ExecuteSQLQuery("update userlogfile set logouttime=CONVERT(datetime,'" & Now.ToString("yyyy-MM-dd HH:mm:ss") & "',101) where transcode=" & UserLogInlogoutID)  

Here ExecuteSQLQuery is User Defined Function

No comments:

Post a Comment

Copyright © MS SQL MS-ACCESS

Sponsored By: GratisDesigned By: Habib Blog