'Whenever I try to search for a record I am met with an error saying that the CustomerID column doesn't exist in the searchDataService function
import sqlite3
def ServiceData():
conn=sqlite3.connect("Service.db")
cur=conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS service(id INTEGER PRIMARY KEY, CustomerID INTEGER, ServiceName text, ServicePrice text, Date text, Time text, ExtraProducts text)")
conn.commit()
conn.close()
def addServiceRec(CustomerID, ServiceName, ServicePrice, Date, Time, ExtraProducts ):
conn=sqlite3.connect("Service.db")
cur=conn.cursor()
cur.execute("INSERT INTO Service VALUES (NULL, ?,?,?,?,?,?)", (CustomerID, ServiceName, ServicePrice, Date, Time, ExtraProducts))
conn.commit()
conn.close()
def searchDataService(CustomerID):
conn=sqlite3.connect("Service.db")
cur=conn.cursor()
cur.execute("SELECT * FROM Service WHERE CustomerID=?", (CustomerID,))
rows=cur.fetchall()
conn.close()
return rows
when ran in the front-end I am told that the CustomerID column by which it searches does not exist yet it is created above this function.
ServiceData()
Error: cur.execute("SELECT * FROM Service WHERE CustomerID=?", (CustomerID,)) sqlite3.OperationalError: no such column: CustomerID
Front end
def search():
Customerlist.delete(0,END)
for rows in cusDatabase_BackEnd.searchData(ID_entry.get()):
rows = list(rows)
for i in range(len(rows)):
rows[i] = str(rows[i]).strip()
Customerlist.insert(END,rows,str(""))
CustomerID = IntVar()
label= Label(window, text="Customer's ID:", font=('arial',13,'bold'))
label.place(x=30, y=100)
ID_entry=ttk.Entry(window, textvariable = CustomerID)
ID_entry.place(x=210,y=100)
ID_entry.focus()
btnSearch2 = tk.Button(window, text="Search record", command = search)
btnSearch2.place(x=1150,y=160, width=125, height=50)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
