2013-09-30 3 views
0

안녕하세요.클래식 ASP에서 데이터베이스 삽입 문제

"Microsoft Jet 데이터베이스 엔진 오류 '80040e14가'

쿼리 식

구문 오류 (누락 된 연산자) 'c_name : 나는 테스트가 내 양식에 제출 한 후 나는이 문장의 구문 오류를 받고 있어요 = '골든 와틀'AND sc_ 이름 = '아카시아 pycnantha'및 URL = 'http://anpsa.org.au/a-pyc.html'AND 이미지 = 'http://anpsa.org.au/jpg/029_2.jpg'AND 가격 = '$ 72'와 정보 = '골든 와틀은 호주의 나라꽃이다.' '.

/courses/benv/2410/2013s2/3420384/연습/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

디버깅 (101) 다음 TSQL 문을 인쇄 할 수있는 인쇄 문을 추가 데이터베이스 엔진으로 전송로 ... –

+0

@MitchWheat 감사합니다 너의 도움으로. 데이터베이스 엔진으로 보낸 SQL 문을 인쇄하고 오류를 발견했습니다. sc 변수는 sn으로 작성되었습니다. 나는 그것을 바꿨다. 그런 다음 다른 오류가 발생했습니다. 'Microsoft JET 데이터베이스 엔진 오류 '80040e14' INSERT INTO 문에 구문 오류가 있습니다. /courses/benv/2410/2013s2/3420384/exercises/ex05/insert-plant.asp, line 61' 오류를 찾기 위해 지금까지 행운을 찾지 못한 문구를 인쇄 해 보았습니다. – chap

+0

이런 종류의 문제에 대한 표준 해결책 : [매개 변수화 된 쿼리] (http://stackoverflow.com/a/18619736/1630171)를 사용하십시오. –

답변

1

인용 부호는해야한다 문에 삽입에서 누락 :

SQL="insert into PlantTable (c_name, sc_name, url, image, price, information) values 
('" & cn & "', '"&sn&"', '"&url&"', '"&image&"', '"&price&"', '"&desc&"');" 

또한 오류 메시지 내림차순에서 "호주"문자열을 구분합니다 작은 따옴표가있다. 이 문제를 해결하려면 변수 내의 작은 따옴표의 수를 두 배로 늘리십시오.

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) 
&"');" 
+0

[본질적으로 깨진 접근법] (http://xkcd.com/327/)을 반창으로 들기를 시도하지 마십시오. –