Home > OS >  Incorrect number of bindings supplied. The current statement uses 10, and there are 11 supplied
Incorrect number of bindings supplied. The current statement uses 10, and there are 11 supplied

Time:08-28

import sqlite3 ,csv
with open("BollywoodMovieDetail.csv","r")as file:
    no_records = 0
    for row in file:
        c.execute("INSERT INTO Movie VALUES(?,?,?,?,?,?,?,?,?,?)", row.split(","))
        conn.commit()
        no_records  = 1
conn.close()
print('\n{} Records Transferred'.format(no_records))

i dont know why the code is terminating my guess is that their is cell which have "," in it amd cousing problem. If it is so please let me know how to fix it. I m new to SQLITE3 so its getting hectic

CodePudding user response:

Your insert statement expects 10 values per record. The error message implies that one or more lines has 11 values after splitting by comma, or, alternatively, one or more lines have 10 commas. You may iterate over your file and try to find the offending line(s):

with open("BollywoodMovieDetail.csv", "r") as file:
    for row in file:
        parts = row.split(",")
        if len(parts) == 11:
            print(row)
  • Related