开发者

Error in number of bindings supplied and values supplied

开发者 https://www.devze.com 2023-03-14 07:07 出处:网络
I am trying to convert an excel sheet into an sqlite3 db using win32com module in python. My excel sheet has 6 columns and so my a part of my python code is:

I am trying to convert an excel sheet into an sqlite3 db using win32com module in python. My excel sheet has 6 columns and so my a part of my python code is:

for row in exceldata:
      c.execute('INSERT INTO exceltable1 VALUES(?,?,?,?,?,?)',row)
conn.commit()

But python gives me the following error:

c.execute('INSERT INTO exceltable VALUES(?,?,?,?,?,?)',row)
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 6, and there are 5 supplied.

If I try to remove one question mark and run it again, the error now becomes:

c.execute('INSERT INTO exceltable1 VALUES(?,?,?,?,?)',row)
OperationalError: table exceltable1 has 6开发者_JAVA百科 columns but 5 values were supplied

Could anyone please explain to me whats happening here and if there is any solution...

Thx.


First of all, make sure what the value of row is, and how many items it has:

 print row, len(row)

Then try and use the complete insert sql statement:

 insert into table (col1, col2, col3, ...) values (?, ?,? ...)

and see what happens. This should solve your problem, or at least let you understand what is happening.


You're telling it that you have 6 columns (arguments), but you're only giving it 1 arguments. This is why it's telling you that you're missing 5 column.

0

精彩评论

暂无评论...
验证码 换一张
取 消