Search code examples
rrodbc

R RODBC sqlUpdate or sqlQuery


I am trying to insert a dataframe into a sql table. The sqlUpdate code gives a inherits(channel, "RODBC") channel is missing error Insertdata<-sqlUpdate(DBcon, df, tablename = "DataQuality", sqlColumns(special=FALSE)) My second attempt was this

Insertdata<-sqlQuery(DBcon,paste("insert into DataQuality", df, sep = ""))

sqlQuery shows an error of

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'Nothing to add'

." (this is the first column and row of data)

"[RODBC] ERROR: Could not SQLExecDirect 'insert into DataQuality(Descriptions,Date,Name,Ref)SELECT Descriptions,Date,Name,Ref FROMc(\"Nothing to add\"

, and seems to stop at the end of the first column.


Solution

  • Insertdata<-sqlSave( DBcon, df, "DataQuality",rownames=FALSE, append=TRUE) This will update the SQL table with the new dataframe.