How to Update or Insert Date Values Into SQL Database
To Insert /Update Date into SQL Server , Use the following method
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
MAINCON.Open()
Try
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
DBF1.ExecuteNonQuery()
DBF1.Dispose()
Catch ex As Exception
End Try
MAINCON.Close()
From the Previous Post, Execute Query is very easy to UPDATE INSERT DELETE .
Example:
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