我在将CSV文件上传到MS SQL Server中的表时遇到问题,该CSV文件有25列,并且标题与SQL中的表具有相同的名称,该表也有25列.当我运行脚本时会引发错误
params arg () can be only a tuple or a dictionary
将此数据导入MS SQL的最佳方法是什么? CSV和SQL表都具有完全相同的列名.
这是代码:
import csv
import pymssql
conn = pymssql.connect(
server="xx.xxx.xx.90",
port = 2433,
user='SQLAdmin',
password='xxxxxxxx',
database='NasrWeb'
)
cursor = conn.cursor()
customer_data = csv.reader('cleanNVG.csv') #25 columns with same header as SQL
for row in customer_data:
cursor.execute('INSERT INTO zzzOracle_Extract([Customer Name]\
,[Customer #]\
,[Account Name]\
,[Identifying Address Flag]\
,[Address1]\
,[Address2]\
,[Address3]\
,[Address4]\
,[City]\
,[County]\

本文介绍如何使用Python将CSV文件批量导入到MS SQL Server中。在尝试使用pymssql库时遇到了错误,最终解决方案是通过pandas的pd_to_mssql函数实现数据导入。
最低0.47元/天 解锁文章

351

被折叠的 条评论
为什么被折叠?



