问题
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: ('Params must be in a list, tuple, or Row', 'HY000')
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,
A few versions:
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()
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)
回答1:
cursor.execute(qry, params[0:8]) worked
The executemany was causing the error - params must be in list, tuple or row
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
Winning answer was:
cursor.execute(qry, params[0:8]) worked
thanks to @gordthompson for his prompt
来源:https://stackoverflow.com/questions/55024559/pyodbc-accessdb-typeerror-params-must-be-in-a-list-tuple-or-row-hy000