create a table from a dataframe using RODBC

送分小仙女□ 提交于 2019-12-13 06:49:21

问题


I am connecting to a SQL Server using ODBC and want to create a table from a dataframe. Following RODBC vignette below is my code,

library(RODBC) 
channel <- odbcConnect("DSN#", uid = "uname", pwd = "pwd")
ana.cars.df <- data.frame(mtcars)
sqlSave(channel, ana.cars.df)

And below is the error that I am getting

Error in sqlSave(channel, ana.cars.df) : 42000 102 [FreeTDS][SQL Server]Incorrect syntax near 'rownames'. [RODBC] ERROR: Could not SQLExecDirect 'CREATE TABLE ana.cars.df ("rownames" varchar(255), "mpg" float, "cyl" float, "disp" float, "hp" float, "drat" float, "wt" float, "qsec" float, "vs" float, "am" float, "gear" float, "carb" float)'

I have tried other options such as append = TRUE, rownames = FALSE, etc but the nature of the error is same.

来源:https://stackoverflow.com/questions/35440662/create-a-table-from-a-dataframe-using-rodbc

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