SQL 插入日期/时间和JavaScript 中获取的值

发布于 2024-11-08 05:25:20 字数 1223 浏览 0 评论 0原文

我正在尝试将当前日期/时间和重定向到此错误页面的值插入到访问数据库中。到目前为止,唯一的问题来自当我将重定向值添加到插入语句中时。这是我的代码。

errnum = Request.QueryString("errnum")
prevPageTitle = request.querystring("pagetitle")

Function AccessDateTime (dateandtime)
Dim myDay
Dim myMonth
Dim myYear

myDay = Day(dateandtime)
If Len(myDay)=1 Then myDay="0" & myDay

myMonth = Month(dateandtime)
If Len(myMonth)=1 Then myMonth="0" & myMonth

myYear = Year(dateandtime)

AccessDateTime = myYear & "-" & myMonth & "-" & myDay & " " & Time()
End Function

Dim connection
Dim SQL, sConnString

SQL="INSERT INTO ErrorTable (ErrorTime, ErrorPage) VALUES (#" & AccessDateTime(NOW()) & "#, #" & prevPageTitle & "#)"   
//////This is where the issue is, ErrorPage column isn't updated with prevPageTitle acquired information. 

(Error Type:
Microsoft JET Database Engine (0x80040E07)
Syntax error in date in query expression '#Pre-ErrorPage.asp#'.//////

sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("ErrorTimeLog.mdb")
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open(sConnString)
connection.execute(SQL)

Connection.Close
Set Connection = Nothing

I am trying to insert current date/time and a value that was redirected to this errorpage into an access database. So far the only issue is coming from when i add the redirected value into the insert statement. Here is my code.

errnum = Request.QueryString("errnum")
prevPageTitle = request.querystring("pagetitle")

Function AccessDateTime (dateandtime)
Dim myDay
Dim myMonth
Dim myYear

myDay = Day(dateandtime)
If Len(myDay)=1 Then myDay="0" & myDay

myMonth = Month(dateandtime)
If Len(myMonth)=1 Then myMonth="0" & myMonth

myYear = Year(dateandtime)

AccessDateTime = myYear & "-" & myMonth & "-" & myDay & " " & Time()
End Function

Dim connection
Dim SQL, sConnString

SQL="INSERT INTO ErrorTable (ErrorTime, ErrorPage) VALUES (#" & AccessDateTime(NOW()) & "#, #" & prevPageTitle & "#)"   
//////This is where the issue is, ErrorPage column isn't updated with prevPageTitle acquired information. 

(Error Type:
Microsoft JET Database Engine (0x80040E07)
Syntax error in date in query expression '#Pre-ErrorPage.asp#'.//////

sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("ErrorTimeLog.mdb")
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open(sConnString)
connection.execute(SQL)

Connection.Close
Set Connection = Nothing

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许久 2024-11-15 05:25:20

以防万一有人需要类似问题的答案。问题出在我的 SQL 语句的语法中。

SQL="INSERT INTO ErrorTable (ErrorTime,ErrorPage,ErrorNumber) VALUES (#" & AccessDateTime(NOW()) & "#, '" & prevPageTitle & "', '" & errnum & "')"

所获取的变量需要单引号。

Just in case anyone needs an answer to a similar question. The issue was in the syntax of my SQL statement.

SQL="INSERT INTO ErrorTable (ErrorTime,ErrorPage,ErrorNumber) VALUES (#" & AccessDateTime(NOW()) & "#, '" & prevPageTitle & "', '" & errnum & "')"

Single quotes were needed around the acquired variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文