执行ASP ADO插入时出现语法错误

时间:2013-01-01 21:27:48

标签: asp-classic ado

我正在连接不同的值,我得到以下sql语句:

INSERT INTO Ads (Position, Type, AdType, Link, Width, Height, Path, Korder ) VALUES ('left','1','left1','',1024,768,'FILE1',1)

我真的没有看到任何错误,但是,它说我

Microsoft JET数据库引擎错误“80040e14”

INSERT INTO语句中的语法错误。

/adm/uploadAdPic.asp,第68行

sql="INSERT INTO Ads (Position, Type, AdType, Link, Width, Height, Path, Korder )"
            sql=sql & " VALUES "
            sql=sql & "('" & position & "',"
            sql=sql & "'" & adType & "',"
            sql=sql & "'" & position & adType & "',"
            sql=sql & "'" & link & "',"
            sql=sql & "" & width & ","              
            sql=sql & "" & height & ","
            sql=sql & "'" & path & "',"
            //sql=sql & "" & korder & ","
            sql=sql & "" & korder & ")"
            //sql=sql & "0)"

            Response.Write(sql)

            //on error resume next
            conn.Execute sql,recaffected      //THIS IS LINE 68

请你帮我找一下语法错误。

编辑: 我自己找到了溶剂,但它也包含在下面的答案中。 位置是保留字。 我试图修改我的插入语句删除不同的字段,我发现位置字段出错。 所以我将Position重命名为VertPos并且它可以工作。

2 个答案:

答案 0 :(得分:2)

位置是Jet SQL中的保留字,请尝试更改为[位置]。

作为一般建议,将[]添加到所有列名称。

    sql="INSERT INTO Ads ([Position], [Type], [AdType], [Link], [Width], [Height], [Path], [Korder] )"
                sql=sql & " VALUES "
                sql=sql & "('" & position & "',"
                sql=sql & "'" & adType & "',"
                sql=sql & "'" & position & adType & "',"
                sql=sql & "'" & link & "',"
                sql=sql & "" & width & ","              
                sql=sql & "" & height & ","
                sql=sql & "'" & path & "',"
                //sql=sql & "" & korder & ","
                sql=sql & "" & korder & ")"
                //sql=sql & "0)"

                Response.Write(sql)

                //on error resume next
                conn.Execute sql,recaffected      //THIS IS LINE 68

答案 1 :(得分:1)

1)错误是因为您的某些列名恰好是MSSQL关键字:

' SUGGESTED CHANGE:
INSERT INTO Ads (
  [Position], [Type], [AdType], [Link], [Width], [Height], [Path], [Korder]) 
VALUES ('left','1','left1','',1024,768,'FILE1',1)

2)使用命令对象而不是“裸插入”可能会好得多:

Here's an example that shows how to use "objCom.parameters.append()":