('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to int. (8114) (SQLExecDirectW)')

StackOverflow https://stackoverflow.com/questions/22206337

  •  09-06-2023
  •  | 
  •  

Pergunta

I am trying use pyodbc execute a Stored Procedures

('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to int. (8114) (SQLExecDirectW)') with the User_id number field.

Here is my code:

jsonData = json.loads(data)
user_id = jsonData['user']['id']
Sreenname = jsonData['user']['screen_name']
name = jsonData['user']['name']


con.execute("exec sp_insertintoalltable user_id,Sreenname,name")
Foi útil?

Solução

Your con.execute() statement is not automatically picking the user_id, Sreenname and name variables from Python; you need to pass those in explicitly, using bind parameters:

con.execute("exec sp_insertintoalltable ?, ?, ?", (user_id, Sreenname, name))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top