Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PYODBC-参数太少_Python_Sql_Pyodbc - Fatal编程技术网

Python PYODBC-参数太少

Python PYODBC-参数太少,python,sql,pyodbc,Python,Sql,Pyodbc,我有以下代码: Late_Students = cursor.execute(''' SELECT Student.Forename, Student.Surname, FORMAT(Event_Date_Time,"Long Time") AS Time_Of_Event FROM Events, Student WHERE FORMAT(Event_Date_Time,"Short Date") = Date() AND Events.RFID = Stude

我有以下代码:

Late_Students = cursor.execute('''
    SELECT Student.Forename, Student.Surname, FORMAT(Event_Date_Time,"Long Time") AS Time_Of_Event
    FROM Events, Student
    WHERE FORMAT(Event_Date_Time,"Short Date") = Date()
    AND Events.RFID = Student.RFID AND
    Events.In_Or_Out = ?
    AND FORMAT(Event_Date_Time,"Long Time")>#08:40:00#''','In')

rows = cursor.fetchall()
print(rows)
这是一个非常简单的方法,我的程序中有很多类似的方法,但是当我运行程序时,我得到以下错误:

Traceback (most recent call last):
  File "...Coursework System 1.8.py", line 104, in <module>
    AND FORMAT(Event_Date_Time,"Long Time")>#08:40:00#''','In')
pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver]
                         Too few parameters. Expected 3. (-3010) (SQLExecDirectW)')
回溯(最近一次呼叫最后一次):
文件“…课程作业系统1.8.py”,第104行,在
和格式(事件日期时间,“长时间”)>(08:40:00“,”In“)
pyodbc.Error:('07002','[07002][Microsoft][ODBC Microsoft Access驱动程序]
参数太少。应为3。(-3010)(SQLExecDirectW)“”)
添加参数时,出现以下错误,告诉我参数太多:

Traceback (most recent call last):
  File "...\Coursework System 1.8.py", line 104, in <module>
    AND FORMAT(Event_Date_Time,"Long Time")>#08:40:00#''','In','','')
pyodbc.ProgrammingError: ('The SQL contains 1 parameter markers, but 3
                           parameters were supplied', 'HY000')
回溯(最近一次呼叫最后一次):
文件“…\Coursework System 1.8.py”,第104行,在
和格式(事件日期时间,“长时间”)>(08:40:00“,”In“,”In“,”)
pyodbc.ProgrammingError:('SQL包含1个参数标记,但包含3个参数标记
提供了参数(“HY000”)

我做错了什么?

可能是@PeterWood的复制品我已经尝试了发布在那里的解决方案,但没有效果。由于某些原因,它仍然不起作用。那么您会遇到什么错误?与之前相同的错误将查询中的所有内容更改为参数解决了此问题。谢谢:)
Long_Time = 'Long Time'
Short_Date = 'Short Date'
Todays_Date = time.strftime('%d/%m/%Y')
Reg_Time = str('#08:40:00#')
In = 'In'

Late_Students = '''
                SELECT Student.Forename, Student.Surname, FORMAT(Event_Date_Time,?) AS Time_Of_Event
                FROM Events, Student
                WHERE FORMAT(Event_Date_Time,?) =?
                AND Events.RFID = Student.RFID AND
                Events.In_Or_Out =?
                AND FORMAT(Event_Date_Time,?)>?'''

parameters = (Long_Time, Short_Date,Todays_Date, In, Long_Time, Reg_Time)
cursor.execute(Late_Students, parameters)