How to insert a dataframe into a SQL Server table?

后端 未结 3 564
梦毁少年i
梦毁少年i 2020-12-05 05:29

I\'m trying to upload a dataframe to a SQL Server table, I tried breaking it down to a simple SQL query string..

library(RODBC)
con <- odbcDriverConnect(\         


        
3条回答
  •  感情败类
    2020-12-05 05:54

    This worked for me and I found it to be simpler.

    library(sqldf)
    library(odbc)
    con <- dbConnect(odbc(),
                     Driver = "SQL Server",
                     Server = "ServerName",
                     Database = "DBName",
                     UID = "UserName",
                     PWD = "Password")
    dbWriteTable(conn = con, 
                 name = "TableName", 
                 value = x)  ## x is any data frame
    

提交回复
热议问题