2011-05-19 76 views
0

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

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 

回答

0

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

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

在采集的变量周围需要单引号。