Я пытаюсь прочитать файл Excel в фрейме данных Python для панд, а затем добавить фрейм данных в существующую базу данных Access.
Я получил следующую ошибку:
Ошибка ('HYC00', '[HYC00] [Microsoft] [ODBC Microsoft Access Driver] Не реализована дополнительная функция (106) (SQLBindParameter)')
Я прочитал, что эта ошибкаобычно является результатом pyodbc 4.0.25.Я понизил версию до pyodbc 4.0.24 и все еще получаю сообщение об ошибке.
import glob
import os
import pandas as pd
import time
import pyodbc
# specify the folder that the files are sitting in
list_of_files = glob.glob(r'C:\Users\CraigG\Test\*xlsx')
# define the newest file in the folder
filename = min(list_of_files, key=os.path.getmtime)
# put excel file in data frame
df = pd.read_excel(filename)
print(pyodbc.version)
conn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};' +
r'DBQ=C:\\Users\\CraigG\\Test\\Db\\Master.accdb;')
cursor = conn.cursor()
for index, row in df.iterrows():
AccountNum = row["Account #"]
CustomerNum = row["Customer #"]
CustomerName = row["Customer Name"]
AccountName = row["Account Name"]
SalesRegisterNum = row["Sales Register #"]
InvoiceDate = row["Invoice Date"]
BillingMonthDate = row["BillingMonthDate"]
WrittenBy = row["Written By"]
Mfr = row["Mfr"]
CatalogNo = row["CatalogNo"]
LineType = row["LineType"]
UPC = row["UPC"]
QTYShip = row["QTY Ship"]
Price = row["Price"]
PriceUOM = row["Price UOM"]
ExtenedPrice = row["Extened Price"]
Cost = row["Cost"]
CostUOM = row["Cost UOM"]
ExtendedCost = row["Extended Cost"]
SPACost = row["SPA Cost"]
SPACostUOM = row["SPA Cost UOM"]
ExtendedSPACost = row["Extended SPA Cost"]
PCNum = row["PC #"]
sql = "INSERT INTO Master ([Account #], [Customer #], [Customer Name], [Account Name], [Sales Register #], [Invoice Date], [BillingMonthDate], [Written By], [Mfr], [CatalogNo], [LineType], [UPC], [QTY Ship], [Price], [Price UOM], [Extened Price], [Cost], [Cost UOM], [Extended Cost], [SPA Cost], [SPA Cost UOM], [Extended SPA Cost], [PC #]) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
params = (AccountNum, CustomerNum, CustomerName, AccountName,
SalesRegisterNum, InvoiceDate, BillingMonthDate, WrittenBy, Mfr,
CatalogNo, LineType, UPC, QTYShip, Price, PriceUOM, ExtenedPrice, Cost,
CostUOM, ExtendedCost, SPACost, SPACostUOM, ExtendedSPACost, PCNum)
cursor.execute(sql, params)
cursor.commit()