pyodbc AccessDB TypeError :(“参数必须在列表,元组或行中","HY000") [英] pyodbc AccessDB TypeError: ('Params must be in a list, tuple, or Row', 'HY000')

查看:91
本文介绍了pyodbc AccessDB TypeError :(“参数必须在列表,元组或行中","HY000")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows 7上运行Python 3.7.2 32位并使用pyodbc软件包4.0.25-cp27 32bit

Running Python 3.7.2 32 bit on Windows 7 and using pyodbc package 4.0.25-cp27 32bit

我尝试了多种通过参数的方式,并不断出现上述错误:

I have tried multiple ways of passing through the params and keep getting the above error:

TypeError :(参数必须在列表,元组或行中,'HY000')

TypeError: ('Params must be in a list, tuple, or Row', 'HY000')

我的输入文件是一个包含以下内容的txt文件:

my inputfile is a txt file containing this:

TEST ,EU ,Totals , 30, 0.61, 0.00000000,GOLD ,01/03/2019,   
TEST ,EU ,SubTotals , 40, 0.63, 0.00000000,GOLD ,01/03/2019,

一些版本:

qry = """INSERT INTO newtable ([Col1], [Col2], [Col3], [Col4], [Col5], [Col6], [Col7], [Col8]) VALUES (?,?,?,?,?,?,?,?);"""  

with open (inputfile, "r") as afile:  
    for line in afile:  
        params = tuple(line.split(','))  
        cursor.executemany(qry, params)  
conn.commit()  

的params值也尝试过:

for the params value also tried:

params = list(line.split(','))

还尝试将所有值一一插入到列表中:

Also tried inserting all values into the list one by one:

params = list(line.split(","))  
a = params[0]  
b = params[1]  
c = params[2]  
d = params[3]   
e = params[4]  
f = params[5]  
g = params[6]  
h = params[7]  
dbparams = [a,b,c,d,e,f,g,h]   
cursor.executemany(qry,dbparams) 

推荐答案

cursor.execute(qry,params [0:8])有效

cursor.execute(qry, params[0:8]) worked

executemany导致了错误-参数必须位于列表,元组或行中

The executemany was causing the error - params must be in list, tuple or row

并且没有[0:8]列表通过列表末尾的'\ n'引起错误-SQL包含8个参数标记,但提供了9个参数

and without the [0:8] the list was passing through a '\n' at the end of the list causing the error - the SQL contains 8 parameter markers, but 9 parameters were supplied

获奖答案是:

cursor.execute(qry,params [0:8])有效

cursor.execute(qry, params[0:8]) worked

感谢@gordthompson的提示

thanks to @gordthompson for his prompt

这篇关于pyodbc AccessDB TypeError :(“参数必须在列表,元组或行中","HY000")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆