面临参数太少.预期 1. (-3010) (SQLExecDirectW)')"python程序中的错误 [英] facing Too few parameters. Expected 1. (-3010) (SQLExecDirectW)')" error in python program

查看:108
本文介绍了面临参数太少.预期 1. (-3010) (SQLExecDirectW)')"python程序中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用pythonpyodbc"模块从excel表中提取数据.当我使用数字而不是 win_b64 时,该程序有效,对于字符串,即 win_b64 它显示以下错误.我想检索以下条件中的数据其中平台 = win_b64 和 context_id = 806"

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])

错误:

pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Excel Driver] 参数太少.预期为 1. (-3010) (SQLExecDirectW)')

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

推荐答案

解决方案:

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.

这篇关于面临参数太少.预期 1. (-3010) (SQLExecDirectW)')"python程序中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆