Python and SQLite: insert into table by input
Question:
I am doing this but it still gives me this Error
I am trying to insert data by input into the table
Answers:
Try this:
cr.execute(f"INSERT INTO Family VALUES('{name}',{age},'{Hobby}')")
Python example to insert a single row into SQLite table
1.Connect to SQLite from Python. …
2.Define a SQL Insert query. …
3.Get Cursor Object from Connection. …
4.Execute the insert query using execute() method. …
5.Commit your changes. …
6.Get the number of rows affected. …
7.Verify result using the SQL SELECT query.
I am doing this but it still gives me this Error
I am trying to insert data by input into the table
Try this:
cr.execute(f"INSERT INTO Family VALUES('{name}',{age},'{Hobby}')")
Python example to insert a single row into SQLite table
1.Connect to SQLite from Python. …
2.Define a SQL Insert query. …
3.Get Cursor Object from Connection. …
4.Execute the insert query using execute() method. …
5.Commit your changes. …
6.Get the number of rows affected. …
7.Verify result using the SQL SELECT query.