0

I am concatenating different values and I get the following sql statement:

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

I really do not see here any errors, however, it says me

Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/adm/uploadAdPic.asp, line 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

Can you, please, help me to find syntax error.

EDIT: I have found sollution by myself, but it also contains in the answer below. Position is reserved word. I tried to modify my insert statement removing different fields and I found out that Position field makes an error. So I renamed Position to VertPos and it works.

1
  • But you don't always have the luxury of changing the schema. So keep the Microsoft "[]" syntax in mind. Or the equivalent MySql "``" syntax. Commented Jan 1, 2013 at 23:57

2 Answers 2

2

Position is a reserved word in Jet SQL, try change to [Position].

As a general recommendation, add [] to all columns name.

    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
Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure that all data types are text? Parameters would be much safer.
no, but the error does not indicate a problem of data type. Also it would be nice if the OP tell us the types of each column
1

1) The error is because some of your column names happen to be MSSQL keywords:

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

2) You're probably much better off using a command object instead of a "naked insert":

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.