繁体   English   中英

如何在python代码中使用带有参数的存储过程

[英]how can I use stored procedure with parameters in python code

我想在python代码中使用存储过程,如下所示。

import pyodbc
conn = pyodbc.connect('Trusted_Connection=yes', driver = '{SQL Server}',
                      server = 'ZAMAN\SQLEXPRESS', database = 'foy3') 

def InsertUser(studentID,name,surname,birth,address,telephone):
    cursor = conn.cursor()
    cursor.execute("exec InserttoDB studentID,name,surname,birth,address,telephone")
    rows = cursor.fetchall()

我在代码的一部分下面遇到了问题。 如何使用InserttoDB(存储过程)将函数参数发送到DB

cursor.execute("exec InserttoDB studentID,name,surname,birth,address,telephone")

我不确定你使用的数据库,但我认为这应该可以完成。

cursor.execute("call SP_YOUR_SP_NAME(params)")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM