def insert(self):
conn = pyodbc.connect(
'Driver={SQL Server};'
'Server=DESKTOP-S0VG212\SQLEXPRESS;'
'Database=MovieGuide;'
'Trusted_Connection=yes;'
)
cursor = conn.cursor()
Error occurs when executing the query but I don't know what's causing it.
cursor.execute('insert into Movies(MovieName,Genre,Rating,Username) values(?,?,?,?);',
(self.moviename, self.moviegenre, self.ratebox, self.username))
conn.commit()
I know my answer is late, but it can be useful to someone.
SystemError: <class 'pyodbc.Error'> returned a result with an error set
error appears when the query is wrong, make sure you are executing the correct query using SQL server query window then you can able to identify the problem.
In the question, the semicolon should not come to the end of the query, if you still get an error, it might chances for the column to have some constraint issue. So follow the below method when you are facing this issue.
Execute one insert query in the SQL server query tab and identify the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With