0

I am trying to send a data from my code to SQL Server, but i got this error:

ProgrammingError: 
('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'emotion'. (102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)")

My Code:

import pyodbc 
conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=DESKTOP-T7OFQV6\SQLEXPRESS1;'
                      'Database=VidgaEmotionRecognition;'
                      'Trusted_Connection=yes;')
 
cursor = conn.cursor()
cursor.execute('''INSERT INTO FaceEmotion emotion ?''', index_pred_as_int)

index_pred is a value from previous code snippet.

Structure of FaceEmotion table is like this:

Column: emotion - nvarchar(50) - allows nulls
Column: _id - int - key identity
gvee
  • 16,732
  • 35
  • 50
Gökhan Uçar
  • 191
  • 15
  • 2
    Does this answer your question? [pyodbc the sql contains 0 parameter markers but 1 parameters were supplied' 'hy000'](https://stackoverflow.com/questions/43491381/pyodbc-the-sql-contains-0-parameter-markers-but-1-parameters-were-supplied-hy0) – Guy May 03 '21 at 04:49
  • 1
    Check this answer https://stackoverflow.com/a/43491776/10456732 – Zalak Bhalani May 03 '21 at 04:49
  • I changed my line to this: cursor.execute('''INSERT INTO FaceEmotion emotion ?''', index_pred_as_int) Now my error: ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'emotion'. (102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)") – Gökhan Uçar May 03 '21 at 08:14
  • Please [edit] your question to include the entire `.execute()` statement you are currently using. Do not bury important additional information in the comments. – Gord Thompson May 03 '21 at 11:02
  • I updated my code, could you please help me? – Gökhan Uçar May 04 '21 at 05:16
  • Ignore the Python - your SQL is invalid. `INSERT INTO FaceEmotion (emotion) VALUES ('wink');` – gvee May 04 '21 at 10:00

0 Answers0