0

我正在连接不同的值,我得到以下 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 字段出错。所以我将 Position 重命名为 VertPos 并且它可以工作。

4

2 回答 2

2

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

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

    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
于 2013-01-01T21:32:19.750 回答
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()":
于 2013-01-01T21:40:57.200 回答