【发布时间】:2021-11-16 21:46:57
【问题描述】:
我正在尝试使用 pyodbc 将数据插入到 AZURE SQL 表中。这里我使用了三个 SQL 查询,当我试图将数据插入到表中时,只有最后一个 sql 语句正在插入。
def dbQuery_Multiple_Row(sql,li):
global cursor, conn
cursor, conn =db_connection_dev01()
try:
cursor.execute(sql)
except Exception as e:
li.append("Error-"+str(e))
sql1 = "insert into stars.sampledata values ('Suneel Kummar I', 2, 'Sullurepeta')"
sql2 = "insert into stars.sampledata values ('Suneel Kummar Il', 3, 'Sullurepeta')"
sql3 = "insert into stars.sampledata values ('Suneel Kummar Ill', 4, 'Sullurepeta')"
import pyodbc
sql = [sql1, sql2, sql3]
li = []
dbQuery_Multiple_Row(sql1, li)
dbQuery_Multiple_Row(sql2, li)
dbQuery_Multiple_Row(sql3, li)
conn.commit()
conn.close()
我的任务是我应该为所有 sql 查询提交一次,但提交只发生在最后一个 SQL 查询中。 请帮帮我。提前致谢。
【问题讨论】: