我一直得到这个pyodbc驱动程序错误,我无法解决它任何人都可以帮忙吗?我使用pyqt4与microsoft访问充当数据存储库。忽略任何狡猾的缩进。
这是我的错误:
Traceback (most recent call last):
File "F:\computing\Payroll v2 2\mainwindow.py", line 53, in loadUpcomingBirthdaysForm
self.ui.upcomingBirthdaysForm = UpcomingBirthdays.UpcomingBirthdays()
File "F:\computing\Payroll v2 2\UpcomingBirthdays.py", line 22, in __init__
cursor.execute("select Forename,Surname,DOB from employees where (DOB=?))",9)
pyodbc.Error: ('HYC00', '[HYC00] [Microsoft][ODBC Microsoft Access Driver]Optional feature not implemented (106) (SQLBindParameter)')
这是我的代码:
from PyQt4 import uic
from PyQt4 import QtCore,QtGui
import validation
import pyodbc
import datetime
( Ui_UpcomingBirthdays, QMainWindow ) = uic.loadUiType( 'UpcomingBirthdays.ui' )
class UpcomingBirthdays ( QMainWindow ):
"""Upcoming Birthdays inherits QMainWindow"""
def __init__ ( self, parent = None ):
QMainWindow.__init__( self, parent )
self.ui = Ui_UpcomingBirthdays()
self.ui.setupUi( self )
today = datetime.date.today()
thismonth= int(today.strftime("%m")[0:2])
thisday= int(today.strftime("%d")[0:2])
cnxn = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=F:\\computing\\Payroll v2 2\\employees.accdb')
cursor = cnxn.cursor()
cursor.execute("select Forename,Surname,DOB from employees where (DOBmonth=?))",thismonth)
residentList = cursor.fetchall()
cnxn.close()
self.ui.residentTableWidget.setRowCount(0)
for item in residentList:
print (item)
rowcount = self.ui.residentTableWidget.rowCount()
self.ui.residentTableWidget.insertRow(rowcount)
self.ui.residentTableWidget.setItem(rowcount,0,QtGui.QTableWidgetItem(str(item[0])))
self.ui.residentTableWidget.setItem(rowcount,1,QtGui.QTableWidgetItem(str(item[1])))
self.ui.residentTableWidget.setItem(rowcount,2,QtGui.QTableWidgetItem(str(item[2])))
def __del__ ( self ):
self.ui = None
答案 0 :(得分:3)
我明白了,错误在于以下几行:
cursor.execute("select Forename,Surname,DOB from employees where (DOBmonth=?))",thismonth)
我应该将“thismonth”变量更改为字符串,例如
str(thismonth))