Alexander
Alexander

Reputation: 21

Python to SQLite3

I am making a project where I connect to a database with Python then update and change things. I have run into problems when trying to retrieve information.

I am using this code:

import sqlite3
conn = sqlite3.connect('Project.db')

print ("Opened database sucessfully")

cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")
for row in cursor:
    print ("ID = "), row[0]
    print ("ResidentTitle ="), row[1]
    print ("Name ="), row[2]

print ("done");
conn.close()

from this I am getting back the error:

Traceback (most recent call last):
File "C:/sqlite/Sqlplz.py", line 7, in <module>
cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")
sqlite3.OperationalError: no such table: Residents

How can I resolve this error?

Upvotes: 2

Views: 88

Answers (2)

Alexander
Alexander

Reputation: 21

Problem is fixed, issue with a broken save file.

Upvotes: 0

Adem &#214;ztaş
Adem &#214;ztaş

Reputation: 21446

cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROMResidents")
-------------------------------------------------------------------^

You are missing space, you should update like that

cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")

Upvotes: 1

Related Questions