2013-11-20 75 views
0

我想我pos_DATE,pos_TIME等變量添加到我的數據庫,並得到下面的錯誤顯示,儘管它顯示61行,我相信這是一個SQL問題,而不是上線61缺少運營商

<%@ Language=VBScript %> 

<% 
' make VB declare all variables 
option explicit 

' variable listing and usage 
DIM conx ' connection object to the server 
DIM comd ' instance of a command object 
DIM sql_comd ' string variable to hold the SQL commands 
DIM itemsAdded ' numeric var to hold num records added to table (1 or 0) 
DIM dbpath ' path to the database file 

' create an ado (activeX data object) connection on the server... 
set conx=server.CreateObject("ADODB.connection") 

' Create a "DSN-less" connection to database using OLEDB 
dbpath = Server.Mappath("db/unibookv2.mdb") 
conx.Provider="Microsoft.Ace.OLEDB.12.0" 
conx.Mode = 3 ' adModeReadWrite 
conx.Open dbpath ' open the database 

' instantiate a command object to create a new record via SQL 
set comd=server.CreateObject("ADODB.Command") 
' tell the command object which is the active connection 
comd.ActiveConnection=conx 


' ####################################################### 
' ----------------------------------------------------------------------- 
' The following code checks for errors in user input not picked up by 
' any client side JavaScript and can be omitted initially 
' ----------------------------------------------------------------------- 
DIM pos_DATE 
DIM pos_TIME 

pos_DATE = request ("DATE") 
pos_TIME = request ("TIME") 

if NOT ISDate(pos_TIME) Then 
    pos_TIME = "00:00:00" 
end if 


if NOT ISDate(pos_DATE) Then 
    pos_DATE = "01/01/00" 
end if 


sql_comd="INSERT INTO post (pos_USERID, pos_caption, pos_content, pos_DATE, pos_TIME) VALUES('" &_ 
request("pos_USERID") & "','" & _ 
request("pos_caption") & "','" & _ 
request("pos_content") & "','" & _ 
pos_DATE & "'," & _ 
pos_TIME & ")" 



comd.CommandText=sql_comd ' this is the SQL Insert command sent to the DBMS 
' This line executes the SQL against the DBMS (in this case "MS Access") using the ADO command object 
comd.Execute itemsAdded ' use the execute method of the command object, return number of items added (if any), errors in your SQL will show as being in THIS line not the SQL line..! 
%> 

<h2>ASP - Demo of Add Record to Database table using SQL </h2> 

    <!-- draw an HTML separator line --> 
    <hr align="left" width="758" /><br /> 
    <p>&nbsp;</p> 

    <% 
    ' this is where we use the 'itemsAdded' variable 
    If itemsAdded=1 Then 
     ' message to confirm 1 added record 
     Response.Write "<h3>New record saved successfully to 'testtable'</h3>" 
    Else 
     ' message in red (oops no CSS!) to alert user of an error 
     Response.Write "<h3 style='color:red;'>ERROR - record NOT saved'</h3>" 
    End if 
    %> 

' processing done therefore tidy up... close and destroy any objects used to conserve server resources 
conx.close 
set conx=nothing 
set comd=nothing 


%> 

錯誤代碼如下,謝謝你的幫助。

Microsoft Access Database Engine error '80040e14' 

Syntax error (missing operator) in query expression '00:00:00'. 

/student/s0190204/WIP/addpost.asp, line 61 

回答

2

是pos_TIME一個字符串?如果是的話,你在sql_comd結尾的pos_TIME附近缺少''。