简体   繁体   中英

SQL Insert date/time & acquired value in JavaScript

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM