0

I'm being forced to use python and pyodbc to do some basic database work and am encountering the following error which is confusing me:

pypyodbc.DatabaseError: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.')

The error is clear enough, but why it is expecting two parameters is perplexing me because here is the proceeding code which clearly only asks for a single parameter:

    sqlCommand = "SELECT ProductID, Quantity FROM tblJobsProducts WHERE JobID = (?)"
    jobProductData = executeGetSQLCMD(sqlCommand, [jobData[0][0]])

Where jobData[0][0] is the JobID.

and executeGetSQLCMD is:

def executeGetSQLCMD(sqlString, params=[]):
if len(params) <= 0:
    crsr.execute(sqlString)  # executes the SQL command
else:
    crsr.execute(sqlString, params)
return crsr.fetchall()

The executeGetSQLCMD appears to work just fine in all other cases.

Any idea what's wrong?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
ScottishTapWater
  • 3,656
  • 4
  • 38
  • 81
  • 2
    I am unable to reproduce your issue. A common cause of that error is a typo in a column name. Have a look at the results from `[x[3] for x in crsr.columns("tblJobsProducts").fetchall()]` and confirm that you are using the correct column names. – Gord Thompson Mar 26 '17 at 19:02
  • Yeah... It was a typo, thank you! – ScottishTapWater Mar 26 '17 at 19:15

0 Answers0