create a table from a dataframe using RODBC

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.

链接地址: http://www.djcxy.com/p/30948.html

上一篇: 用R中的nlsList进行非线性回归

下一篇: 使用RODBC从数据框创建表