我正在尝试在Access中创建一个文件排序数据库,我知道如何将一个单词插入到一个单元格/列中。
import pypyodbc
con = pypyodbc.connect("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/Kaiser/Desktop/AccessSPA;DBQ=C:/Users/Kaiser/Desktop/AccessSPA/UDC1.accdb")
cursor = con.cursor()
#cursor.execute(''' DELETE FROM tblLogfile where RDBID = xx''')
cursor.execute(''' INSERT INTO tblLogfile (Filename) VALUES ('test')''')
cursor.commit()
cursor.close()
con.close()
但是我如何插入一整套单词?我有一个文件名和数组的数组,我想插入我的数据库。一列带有alla文件名,列带有相应的归档。下面的例子代码
import pypyodbc
con = pypyodbc.connect("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/Kaiser/Desktop/AccessSPA;DBQ=C:/Users/Kaiser/Desktop/AccessSPA/UDC1.accdb")
array1 = [] # filenames
array2 = [] # filedate
cursor = con.cursor()
#cursor.execute(''' DELETE FROM tblLogfile where RDBID = xx ''')
cursor.execute(''' INSERT INTO tblLogfile (Filename, Filedate) VALUES (array1, array2)''')
cursor.commit()
cursor.close()
con.close()
我将非常感谢帮助,谢谢
答案 0 :(得分:0)
一种简单的方法是循环数组并为数组的每对元素插入一条记录。