facing Too few parameters. Expected 1. (-3010) (SQ

2019-09-10 02:39发布

using python "pyodbc" module for extarcting data from excel sheet. When I use numeric instead of win_b64, This program works, for string i.e. win_b64 It is showing below error. I want to retrive data like in below condition "where platform = win_b64 and context_id = 806"

import pyodbc
exFile = r'C:\Python34\abc.xls'conn1 = pyodbc.connect('DRIVER={MicrosoftExcel Driver (*.xls)};DBQ='+exFile,autocommit=True)

curs1 = conn1.cursor()
excel = curs1.execute('select [problem_name] from [Sheet1$] where platform_name = win_b64 ;').fetchall()
p = (excel)
for x in p:
    print(x[0])

Error:

pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Excel Driver] Too few parameters. Expected 1. (-3010) (SQLExecDirectW)')

1条回答
倾城 Initia
2楼-- · 2019-09-10 03:22

Solution:

excel = curs1.execute('''select [problem_name] from [Sheet1$] where platform_name = 'win_b64' ;''').fetchall() 

-> query syntax should be start in triple quot...and end too.

查看更多
登录 后发表回答