Unable to Append to Table with Autonumber Column with RODBC

こ雲淡風輕ζ 提交于 2019-12-11 03:43:24

问题


I'm attempting to insert a new row to a table in a Microsoft Access database using RODBC. Problem is the primary key column is an autonumber, and it doesn't seem to let me omit this column. I am using the sqlSave function with append = TRUE and a data frame with a single row. I have tried the following:

1: Leaving the column out of the dataframe entirely. This results in the error:

Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test,  : 
   missing columns in 'data'

2: Setting the value of the primary key column to integer NA. This gives me:

Error in sqlSave(conn, exptrow, table = "archiverapp_experiments", append = TRUE,  : 
  unable to append to table ‘archiverapp_experiments’

And the diver error with verbose = TRUE:

23000 -1504 [Microsoft][ODBC Microsoft Access Driver] You tried to assign the Null value to a variable that is not a Variant data type.

3: Setting the value of the PK to zero, as I saw in an answer in another StackOverflow post. This worked the first time but actually sets the PK explicitly to zero, so it doesn't work again.

I suppose I can just do a query before adding to find the maximum value of the PK column, then just add one to that. That seems to defeat the purpose of the autonumber column, however. Is there an easier or more elegant solution?

来源:https://stackoverflow.com/questions/25023731/unable-to-append-to-table-with-autonumber-column-with-rodbc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!