运行以下 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 行的电子表格。