Click here to Skip to main content
15,888,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have using the SQLite3 to insert the multiple records with the placeholder, however I have encounter the above issues.

However, when I run the code it was appear the error
"
InterfaceError: Error binding parameter 0 - probably unsupported type."

My code are as follow:

What I have tried:

<pre lang="Python">
import sqlite3

conn = sqlite3.connect("my_db.db")
c = conn.cursor()
print("SQLite database connected")

my_data = [
    (None, 'Sarah', 'Six', 78, 'Female'),
    (None, 'Davis', 'Four', 55, 'Male'),
    (None, 'Ronald', 'Three', 89, 'Male'),
    (None, 'Sarah', 'Nine', 94, 'Female'),
    (None, 'Peter', 'Seven', 88, 'Male')
]

c.execute("INSERT INTO student VALUES(?,?,?,?,?)", my_data)

print("f'{c} Student record was added")
conn.commit()
conn.close()
print("id of last row added:", c.rowcount)


How should I resolve?
Posted
Comments
CHill60 28-Feb-24 4:53am    
Shouldn't that be
c.execute("INSERT INTO student VALUES(?,?,?,?,?)", my_data,)
i.e. a comma after my_data?
Richard MacCutchan 28-Feb-24 4:58am    
No, I don't think so, but I do think it should be c.executemany( .... Although, there is still the issue of using None for the first value.
Richard MacCutchan 28-Feb-24 4:54am    
Why are you using "None" for the first value in each set? Where is the definition of your student table?
Member 15783420 28-Feb-24 9:00am    
It worked c.executemany instead of c.execute, you are right!

1 solution

Quote:
It worked c.executemany instead of c.execute, you are right!


Added to remove from Unanswered queue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900