Punda
Punda

Reputation: 21

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

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

Upvotes: -1

Views: 99

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521249

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)

Upvotes: 1

Related Questions