Reputation: 1035
exp = "Ted is a good film"
cursor.execute ("insert into films (descp) values (exp)")
cursor.commit()
I'm using above code with MS SQL server, but it says: Invalid column name'exp' I'm using pyodbc.
Upvotes: 0
Views: 3541
Reputation: 212885
I think you should pass it as a tuple:
cursor.execute ("insert into films (descp) values (?)", (exp,))
Upvotes: 3
Reputation: 502
You need introduce exp
content into insert expression as string. You can use string format and ' ':
exp = "Ted is a good film"
cursor.execute ("insert into films (descp) values ('{exp}')".format(exp=exp))
cursor.commit()
Upvotes: 1