Now() 在 ODBC SQL 查询中?
我正在尝试将数据库字段更新为当前时间,但无法传递“now()”。我收到以下错误:
'`now`' is not a recognized built-in function name.
我用来查询数据库的方法如下:
Public Sub main()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.Open "ConnectionName"
rst.ActiveConnection = cnn
rst.CursorLocation = adUseServer
rst.Source = "Update Table ..."
rst.Open
Set rst = Nothing
Set cnn = Nothing
End Sub
I'm trying to update a database field to the current time, but can't pass "now()". I get the following error:
'`now`' is not a recognized built-in function name.
The method I'm using to query the database is as follows:
Public Sub main()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.Open "ConnectionName"
rst.ActiveConnection = cnn
rst.CursorLocation = adUseServer
rst.Source = "Update Table ..."
rst.Open
Set rst = Nothing
Set cnn = Nothing
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Now()
是一个 VBA 函数。您想要做的是使用等效的 SQL 函数,但这取决于您要连接的数据库。如果您要连接的是 SQL Server,请使用
GETDATE()
(对于当地时间)或GETUTCDATE()
(对于 UTC 时间)。Now()
is a VBA function. What you want to do is use the equivalent SQL function, but that depends on the database that you're connecting to.If it's SQL Server you're connecting to, use
GETDATE()
(for local times) orGETUTCDATE()
(for UTC times).尝试 getdate() 函数或 CURRENT_TIMESTAMP
Try getdate() function or CURRENT_TIMESTAMP