你好。在我的表单上进行测试提交后,我在此语句中出现语法错误:
“Microsoft JET数据库引擎错误'80040e14'
查询表达式中的语法错误(缺少运算符)'c_name ='Golden Wattle'AND sc_name ='Acacia pycnantha'AND url ='http://anpsa.org.au/a-pyc.html'AND image ='http://anpsa.org.au/jpg/029_2.jpg'AND price =' $ 72'和信息='金荆是澳大利亚的国家花卉徽章。''。
/courses/benv/2410/2013s2/3420384/exercises/ex05/insert-plant.asp,第54行“
对于我的生活,我不能理解这里的错误。
dim cn, sc, url, image, price, desc
cn=Request.Form("new_cn")
sc=Request.Form("new_sc")
url=Request.Form("new_url")
image=Request.Form("new_image")
price=Request.Form("new_price")
desc=Request.Form("new_desc")
'--- check to see whether there already are items of that name...
SQL="select ID from PlantTable where c_name='"& cn & "' AND sc_name='" & sc & "'"&_
" AND url='"&url& "' AND image='"&image& "' AND price='"&price& "' AND information='"&desc& "' "
set info = conn.execute(SQL)
if info.eof then
'--- there is no plant of that name at present, so do the insert
SQL="insert into PlantTable (c_name, sc_name, url, image, price, information) values ('" & cn & "', "&sn&","&url&","&image&","&price&","&desc&")"
conn.execute(SQL)
response.write "Insertion completed."
else
'--- there is already a plant of that name...
response.write "Sorry, that Plant Name is already in the database."
end if
答案 0 :(得分:1)
Insert into语句中缺少引号,应该是:
SQL="insert into PlantTable (c_name, sc_name, url, image, price, information) values
('" & cn & "', '"&sn&"', '"&url&"', '"&image&"', '"&price&"', '"&desc&"');"
同样在错误消息中,desc“Australia's”有单引号,用于分隔字符串。要解决此变量内部单引号的数量。可以使用以下功能:
Public Function ReplaceSingleQuotes(varValue As Variant) As String
Const SINGLEQUOTE = "'"
ReplaceSingleQuotes = SINGLEQUOTE & _
Replace(varValue, SINGLEQUOTE, SINGLEQUOTE & SINGLEQUOTE) & _
SINGLEQUOTE
End Function
可以用作:
SQL="insert into PlantTable (c_name, sc_name, url, image, price, information) values
('" & cn & "', '"&sn&"', '"&url&"', '"&image&"', '"&price&"', '"& ReplaceSingleQuotes(desc)
&"');"