Search code examples
sqljspms-accesssql-insertautonumber

Insert statement in sql with one field set as autonumber


I am having three columns in my table branch i.e id(Autonumber),code(text),desc(text).I am trying to execute this sql insert into branch(code,desc) values('"+b+"','"+c+"')"; which gives me error syntax error..please help


Solution

  • One of your columns has name DESC, which is Reserved Keyword. In order to peoperly execute the INSERT statement, you need to delimite the column by using brackets eg

    insert into branch(code,[desc]) values ('"+b+"','"+c+"')";
    

    One more thing, your code is prone to SQL Injection. Please do parameterized the query.