2011-05-19 48 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 & "')" 

在採集的變量周圍需要單引號。