我在更新现有Access表时遇到问题。我有一个Access数据库,它应该对一些包含两列的.log文件进行排序:filename
和filedate
。我有文件名并在我通过100多个.log文件排序中制作的Excel文件中提交,因此有100多个文件应该链接到Access
我每次都会收到错误,并尝试了很多不同的事情。问题是我不知道如何编写语法。请有人帮帮我吗?我想要A -> filename
和B -> filedate
,以便每对都有自己的ID
import pypyodbc
UDC = r'C:\Users\Kaiser\Documents\Access\UDC.accdb'
# DSN Connection
#constr = " DSN=MS Access Database; DBQ={0};".format(UDC)
# DRIVER connection
constr = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:/USERS/DOCUMENTS/ACCESS;DBQ=C:/USERS/DOCUMENTS/ACCESS/UDC.accdb"
# Connect to database UDC and open cursor
db = pypyodbc.connect(constr)
cursor = db.cursor()
sql = "UPDATE * INTO [tblLogfile]" + \
"FROM [Excel 8.0;HDR=YES;Database=C:/Users/Documents/Access/Excel.xls].[Tab$];"
cursor.execute(sql)
db.commit()
cursor.close()
db.close()
错误
pypyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.')
答案 0 :(得分:0)
你需要SQL之类的东西:
sql = "INSERT INTO [tblLogfile] (<list of field names>) SELECT <list of matching field names> FROM [Excel 8.0;HDR=YES;Database=C:/Users/Documents/Access/Excel.xls].[Tab$];"