将Datetime作为参数传递给PyODBC的存储过程时出错

问题描述 投票:0回答:1

我需要从Python执行存储过程。我正在使用pyodbc来做到这一点。存储过程需要传递datetime参数。

我使用以下代码:

cursor.execute('exec [Data].[GetData]?',datetime.datetime.now())

我收到以下错误:

ProgrammingError:('42000','[42000] [Microsoft] [ODBC SQL Server驱动程序] [SQL Server]不允许从数据类型datetime到bigint的隐式转换。使用CONVERT函数运行此查询。(257)(SQLExecDirectW )“)

我该怎么办 ?

python sql-server python-3.x pyodbc
1个回答
1
投票
from datetime import datetime

cursor.execute('exec [Data].[GetData]?',datetime.now())

有相同的错误检查您的导入

© www.soinside.com 2019 - 2024. All rights reserved.