问题
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