我得到一个语法错误在这段代码,软件是说pyodbc错误42000,但我看不到

2024-09-28 21:44:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码中有一个错误,我无法识别问题

current_path=os.path.dirname(__file__)
find_database=os.path.join(current_path, "RDdatabase.accdb")
connection=pyodbc.connect('Driver={Microsoft Access Driver (*.mdb, 
*.accdb)}; dbq=%s;' %find_database)
cursor=connection.cursor()

AMorPM = str(self.ui.timedropdown.currentText())
editedTime = str((self.ui.timelineedit.text())+" "+AMorPM)

cursor.execute("insert into 
Appointments(customername,time,service) 
values(?,?,?)",self.ui.customernamelineed 
it.text(),editedTime,
self.ui.servicelineedit.text())

connection.commit()
connection.close()
self.clearedboxes()#function to clear boxes
QtGui.QMessageBox.about (self, 'Added to database', 'The record has been 
added to the database.')

错误在insert into语句中,如有任何帮助,将不胜感激

Traceback (most recent call last):
  File "addappointment.py", line 35, in addappointment
    cursor.execute("insert into Appointments(customername,time,service)values(?,?,?)"
 ,self.ui.customernamelineedit.text(),editedTime,
  self.ui.servicelineedit.text())#inserts the values into a table
pyodbc.ProgrammingError: ('42000', '[42000] 
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement. 
(-3502) (SQLExecDirectW)')

Tags: topathtextselfuidriverserviceconnection