你好。我得到一個語法錯誤在此聲明後,我做了一個測試我的形式提交:經典asp數據庫插入問題
「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'AND information ='Golden Wattle is Australia's national floral emblem。'。
/courses/benv/2410/2013s2/3420384/Exercises/ex05/insert-plant.asp,line 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
調試101:添加打印語句打印出來的T-SQL語句發送到數據庫引擎... –
@MitchWheat謝謝您的幫助。我打印出一條SQL語句發送到數據庫引擎並發現一個錯誤。 sc變量被寫爲sn。我改變了這一點。然後我收到另一個錯誤: 'Microsoft JET數據庫引擎錯誤'80040e14' INSERT INTO語句中的語法錯誤。 /courses/benv/2410/2013s2/3420384/exercises/ex05/insert-plant.asp,line 61' 我試着打印出聲明,但至今沒有運氣找到錯誤。 – chap
這種問題的典型解決方案:使用[參數化查詢](http://stackoverflow.com/a/18619736/1630171)。 –