I am attempting to write a number of records back to the database from a VB6 application using ADO. The records were read in from the database into an ADODB.Recordset and subsequently updated. I would like to be able to have each record in the set use the current date and time of the database server because I have no confidence that all our machines are time-synchronized. Is there a way to do this without having to query the database for CURRENT_TIMESTAMP (or something similar)? Ideally I’m hoping for some sort of flag that I can set the field value to so that the Recordset works this out on the database server.
See the question in my prototype code below (within the while-loop).
Dim oConn As ADODB.Connection
Dim oRs As ADODB.Recordset
Dim sSQL As String
Dim sColumnName1 As String: sColumnName1 = "UserNID"
Dim sColumnName2 As String: sColumnName2 = "Username"
Dim sColumnName3 As String: sColumnName3 = "LastLoginDTM"
' Open a connection.
Set oConn = New ADODB.Connection
oConn.Open 'my connection string was here
' Make a query over the connection.
sSQL = "SELECT TOP 10 " & sColumnName1 & ", " & sColumnName2 & ", " & sColumnName3 & " " & _
"FROM theTable"
Set oRs = New ADODB.Recordset
oRs.CursorLocation = adUseClient
oRs.Open sSQL, oConn, adOpenStatic, adLockBatchOptimistic, adCmdText
oRs.MoveFirst
While Not oRs.EOF
oRs.Fields(sColumnName3).Value = '-=-=-=-=-What do I put here???-=-=-=-=-
oRs.MoveNext
Wend
' Close the connection.
oConn.Close
Set oConn = Nothing
You could use the TSQL GetDate() Function
Change your Select to:
Then, your code could be: