运行以下Python 2.7脚本时,我遇到了一个pyodbc.Error。我正在使用的Excel电子表格中有4行数据。
import pyodbc
from mmap import mmap,ACCESS_READ
import xlrd
import os
#for row_index in range(1,sheet0.nrows):
cnxn = pyodbc.connect('driver={DB};NetworkAddress=DB_Address,Port;Db=DB;uid=login;pwd=password')
cursor = cnxn.cursor()
book=xlrd.open_workbook("I:\\CNLD.xlsx")
sheet=book.sheet_by_index(0)
cell=sheet.cell(1,1)
for rownum in range(sheet.nrows):
print sheet.row_values(rownum)
print sheet.nrows
update_dyna = "insert into tempdb..cm_dyna(secsym,pvsym,min_bid_off,min_bid_offpt,min_ask_off,min_ask_offpt,max_bid_off,max_bid_offpt,max_ask_off,max_ask_offpt) values(?,?,?,?,?,?,?,?,?,?)"
for row_index in range(1, sheet.nrows):
row_num = row_index
secsym = sheet.cell(row_index,0).value
pvsym = sheet.cell(row_index,1).value
min_bid_off = sheet.cell(row_index,2).value
min_bid_offpt = sheet.cell(row_index,3).value
min_ask_off = sheet.cell(row_index,4).value
min_ask_offpt = sheet.cell(row_index,5).value
max_bid_off = sheet.cell(row_index,6).value
max_bid_offpt = sheet.cell(row_index,7).value
max_ask_off = sheet.cell(row_index,8).value
max_ask_offpt = sheet.cell(row_index,9).value
values = (secsym,pvsym,min_bid_off,min_bid_offpt,min_ask_off,min_ask_offpt,max_bid_off,max_bid_offpt,max_ask_off,max_ask_offpt)
cursor.execute(update_dyna,values)
cursor.close()
cnxn.commit()
cnxn.close()
以下是出现的错误信息:
cursor.execute(update_dyna,values)
pyodbc.Error: ('HY000', '[HY000] [DataDirect][ODBC Sybase Wire Protocol driver]Data type for parameter 2 has changed since first SQLExecute call. (0) (SQLExecDirectW)')
cursor.execute
是循环的一部分,所以我不确定为什么不能更新一个只有4行的电子表格。