回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我使用pypyodbc从access数据库中选择数据。我使用下面的查询,其中有三个指定的参数。在</p>
<p>我试过几种品种,但没有效果。我看不出我的语法有什么问题。在</p>
<hr/>
<pre><code>SELECT [Date], [Time], [uSec], [threeR], [twoCV]
FROM [table_a]
WHERE (Date = ? AND Time > ?)
OR (Date > ?)
</code></pre>
<p><strong>参数类型如下:</strong></p>
^{pr2}$
<p><strong>打印时:</strong></p>
<pre><code>1900-09-16 , 00:00:00, 1900-09-16
</code></pre>
<p><strong><em>pypyodbc.DatabaseError:('07002','[07002][Microsoft][ODBC Microsoft Access Driver]参数太少。应为4。“)</em></strong></p>
<pre><code>#-- 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])
</code></pre>
<p><strong>打印1</strong>:[此日期],[此时间],[使用],[三人],[twoCV]</p>
<p><strong>打印2</strong>:从[表a]中选择[此日期]、[此时间]、[uSec]、[三人]、[两人]其中(thisDate=?而这次呢或(thisDate;?),1900-09-16,00:00:00</p>
<hr/>
<p><strong>编辑:</strong>当我删除其中一列时,它似乎成功地执行了。虽然这两列都存在于源表中。这并不能回答为什么原始查询不执行的问题。在</p>
<pre><code>SELECT [Date], [Time], [uSec], [twoCV]
FROM [table_a]
WHERE (Date = ? AND Time > ?)
OR (Date > ?)
</code></pre>
<p><strong>编辑2</strong>:更改日期和时间列的名称不会产生任何影响。以下仍然给出错误:</p>
<pre><code>SELECT [thisDate], [thisTime], [uSec], [threeR], [twoCV]
FROM [table_a]
WHERE ([thisDate] = ? AND [thisTime] > ?)
OR ([thisDate] > ?)
</code></pre>
<p><strong>[Microsoft][ODBC Microsoft Access Driver]参数太少。预期为5。</strong></p>
<p><strong>编辑3</strong>:这是从中提取表的设计视图。
<a href="https://i.stack.imgur.com/SbfEV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SbfEV.png" alt="enter image description here"/></a></p>