python连接access 参数太少_python – PypyODBC参数:[ODBC Microsoft Access Driver]参数太少.预计4...

我正在使用pypyodbc从访问数据库中选择数据.我使用以下查询与三个已指定的参数.

我试过几个品种,但无济于事.我没有看到我的语法有什么问题.

SELECT [Date], [Time], [uSec], [threeR], [twoCV]

FROM [table_a]

WHERE (Date = ? AND Time > ?)

OR (Date > ?)

参数具有以下类型:

[datetime.date, datetime.time, datetime. date]

哪,打印时:

1900-09-16 , 00:00:00, 1900-09-16

pypyodbc.DatabaseError:(‘07002′,'[07002] [Microsoft] [ODBC Microsoft Access驱动程序]参数太少.预计4.’)

#-- Begin Python code sample

#-- Checks the DB file and retrieves data

def pullData(self):

#-- Connect to Access

con = pypyodbc.connect('Driver={Microsoft Access Driver (*.mdb)};DBQ=F:/database.mdb')

cur = con.cursor()

#-- Get column list

columnListODBC = '[thisDate], [thisTime]'

for y in myTable.getColumns():

columnListODBC = columnListODBC + ', [' + y + "]"

#-- See footnote 1

print(columnListODBC)

#-- Get the most recent SQL entry

for row in curSQL.execute('SELECT MAX(Datetime) FROM [' + _.getName() + ']'):

xDateTime = datetime.datetime.strptime(row[0], "%Y-%d-%m %H:%M:%S")

day = xDateTime.date() # Get only the DATE of the most recent entry

time = xDateTime.time() # Get only the TIME of the most recent entry

#-- Pull all ODBC data

queryString = 'SELECT ' + columnListODBC + ' FROM [' + _.getName() + '] WHERE (thisDate = ? AND thisTime > ?) OR (thisDate > ?)'

#-- See footnote 2

print(queryString, ", ", day, ", ", time)

cur.execute(queryString, [day,time,day])

打印1:[thisDate],[thisTime],[uSec],[threeR],[twoCV]

打印2:SELECT [thisDate],[thisTime],[uSec],[threeR],[twoCV] FROM [table_a] WHERE(thisDate =?AND thisTime>?)OR(thisDate>?),1900-09- 16,00:00

编辑:当我删除其中一列时,它似乎成功执行.尽管源表中存在两列.这没有回答关于原始查询不执行的原因的问题.

SELECT [Date], [Time], [uSec], [twoCV]

FROM [table_a]

WHERE (Date = ? AND Time > ?)

OR (Date > ?)

编辑2:更改日期和时间列的名称没有什么区别.以下仍然给出错误:

SELECT [thisDate], [thisTime], [uSec], [threeR], [twoCV]

FROM [table_a]

WHERE ([thisDate] = ? AND [thisTime] > ?)

OR ([thisDate] > ?)

[Microsoft] [ODBC Microsoft Access驱动程序]参数太少.预计5.

编辑3:这是从中拉出的表格的设计视图.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值