[英]sqlite3.OperationalError: near “.”: syntax error
sqlite3.OperationalError:靠近“。”:語法錯誤
當我嘗試填寫表格時出現上述錯誤。
終端:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "c:\Users\username\Desktop\Store Accounting Software\add_to_dy.py", line 64, in get_items
c.execute(sql, (self.name, self.Stock,self.CP, self.SP, self.Total_CP, self.Total_SP, self.Assumed_Profits, self.Vendor, self.Vendor_no))
sqlite3.OperationalError: near ".": syntax error
我在這里查找了所有類似的問題,但找不到解決方案。 這是源代碼,我將不勝感激
from tkinter import *
import sqlite3
import tkinter.messagebox
conn = sqlite3.connect(r"C:\Users\AAJU\Desktop\Store Accounting
Software\Database\store.db")
c = conn.cursor()
class Database:
def __init__ (self, master, *args, **kwargs):
self.master = master
self.heading = Label(master, text = "Add to the database", font=('arial 40 bold'), fg='steelblue')
self.heading.place(x=400, y=0)
self.name_l = Label(master, text="Enter Product Name", font=("arial 18 bold"))
self.name_l.place(x=0, y=70)
self.Stock_l = Label(master, text="Enter Stocks", font=("arial 18 bold"))
self.Stock_l.place(x=0, y=120)
self.CP_l = Label(master, text="Enter Cost Price", font=("arial 18 bold"))
self.CP_l.place(x=0, y=170)
self.SP_l = Label(master, text="Enter Selling Price", font=("arial 18 bold"))
self.SP_l.place(x=0, y=220)
self.Vendor_l = Label(master, text="Enter Vendor Name", font=("arial 18 bold"))
self.Vendor_l.place(x=0, y=270)
self.Vendor_no_l = Label(master, text="Enter Vendor Phone Number", font=("arial 18 bold"))
self.Vendor_no_l.place(x=0, y=320)
# Entries
self.name_e = Entry(master, width=25, font = ("arial 18 bold"))
self.name_e.place(x=380, y=70)
self.Stock_e = Entry(master, width=25, font = ("arial 18 bold"))
self.Stock_e.place(x=380, y=120)
self.CP_e = Entry(master, width=25, font = ("arial 18 bold"))
self.CP_e.place(x=380, y=170)
self.SP_e = Entry(master, width=25, font = ("arial 18 bold"))
self.SP_e.place(x=380, y=220)
self.Vendor_e = Entry(master, width=25, font = ("arial 18 bold"))
self.Vendor_e.place(x=380, y=270)
self.Vendor_no_e = Entry(master, width=25, font = ("arial 18 bold"))
self.Vendor_no_e.place(x=380, y=320)
#Button to add to database
self.btn_add = Button(master, text='Add to database', width = 25, height=2, bg='steelblue', fg = 'white', command=self.get_items)
self.btn_add.place(x=520, y = 370)
#Text Box
self.tbox = Text(master, width=60, height=18)
self.tbox.place(x=750, y=70)
def get_items(self,*args, **kwargs):
#get from entries
self.name = self.name_e.get()
self.Stock = self.Stock_e.get()
self.CP = self.CP_e.get()
self.SP = self.SP_e.get()
self.Vendor = self.Vendor_e.get()
self.Vendor_no = self.Vendor_no_e.get()
self.Total_CP=float(self.CP) * float(self.Stock)
self.Total_SP=float(self.SP) * float(self.Stock)
self.Assumed_Profits = float((self.Total_SP) - (self.Total_CP))
#After I added this block of code i got the error
------------------------------------------------------------------------------
if self.name=='' or self.Stock=='' or self.CP=='' or self.SP=='':
tkinter.messagebox.showinfo('Error','Required Field(s) empty')
else:
sql = "INSERT INTO inventory (Name, Stock, CP, SP, Total_CP, Total_SP, Assumed_Profits, Vendor, Vendor_No. ) VALUES(?,?,?,?,?,?,?,?,?)"
c.execute(sql, (self.name, self.Stock,self.CP, self.SP, self.Total_CP, self.Total_SP, self.Assumed_Profits, self.Vendor, self.Vendor_no))
conn.commit()
tkinter.messagebox.showinfo('Success','Successfully Transferred into the database')
------------------------------------------------------------------------------
root = Tk()
b = Database(root)
root.geometry('1366x768+0+0')
root.title("Add to the database")
root.mainloop()
您在 Vendor_no 之后有一段時間
供應商_編號
在這一行:
sql = “插入庫存(名稱、庫存、CP、SP、Total_CP、Total_SP、Assumed_Profits、Vendor、Vendor_No.)值(?,?,?,?,?,?,?,?,?)"
它不需要在那里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.