Pandas 如何更新包含自动编号列的MS Access表?

Pandas 如何更新包含自动编号列的MS Access表?,pandas,ms-access,pyodbc,Pandas,Ms Access,Pyodbc,我需要在MS Access中使用一个df填充一个表。此表包括一个自动编号列和另一个默认值为now()的列 我试图传递以下数据帧,将ID和RowInsertedTime列保持为空,但这没有成功 d = {'ID': ['',''], 'col1': [1, 2], 'col2': [3, 4], 'RowInsertedTime': ['','']} df = pd.DataFrame(data=d) 我使用pyodbc库执行代码,如下所示: connection_string = (

我需要在MS Access中使用一个df填充一个表。此表包括一个自动编号列和另一个默认值为now()的列

我试图传递以下数据帧,将ID和RowInsertedTime列保持为空,但这没有成功

d = {'ID': ['',''], 'col1': [1, 2], 'col2': [3, 4], 'RowInsertedTime': ['','']}
df = pd.DataFrame(data=d)
我使用pyodbc库执行代码,如下所示:

connection_string = (
    r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
    r'DBQ=C:\Users\Public\MyTest.accdb;'
)
cnxn = pyodbc.connect(connection_string, autocommit=True)
crsr = cnxn.cursor()

# insert the rows from the DataFrame into the Access table    
crsr.executemany(
    f"INSERT INTO [{table_name}] (ID, col1, col2, RowInsertedTime) VALUES (?, ?, ?, ?)",
    df.itertuples(index=False))
很遗憾,这将返回以下错误:

DataError: ('22018', '[22018] [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression. (-3030) (SQLExecDirectW)')

我想知道我的MS-Access表中显示的空白字段的自动值是什么?

您必须省略不更新的列。
crsr.executemany(
    f"INSERT INTO [{table_name}] (col1, col2) VALUES (?, ?)",
    df.itertuples(index=False))
Access将填补空白。

可能的副本