Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
karun_r
Microsoft Employee
Microsoft Employee

R Script error when modifying the dataset- Missing Columns in data

I am trying to insert the dataset that I am receiving from another source into a SQL Server. As there is no option of doing this is native Power BI, I am using R functions to do this. Here is the code that I have:

 

library(RODBC);
serverConn <- odbcDriverConnect(connection="Driver={SQL Server Native Client 11.0};server=<Server>;database=<Database>;trusted_connection=yes;");
sqlSave(serverConn, dataset, tablename ="<tableName>",rownames=FALSE, append = TRUE)

 

When I run this script after loading the dataset, I am getting the below error:

 

DataSource.Error: ADO.NET: R script error.
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test,  : 
  missing columns in 'data'
Calls: sqlSave -> sqlwrite -> odbcUpdate
Execution halted
Warning message:
closing unused RODBC handle 1 

Details:
    DataSourceKind=R
    DataSourcePath=R
    Message=R script error.
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test,  : 
  missing columns in &#39;data&#39;
Calls: sqlSave -&gt; sqlwrite -&gt; odbcUpdate
Execution halted
Warning message:
closing unused RODBC handle 1 

    ErrorCode=-2147467259
    ExceptionType=Microsoft.PowerBI.Radio.RScriptRuntimeException

This error is coming at line 3. I have uncommented it and ran the step and it was working fine. Any idea why this is happening? This same code is running fine when I run it from R console.

1 ACCEPTED SOLUTION
karun_r
Microsoft Employee
Microsoft Employee

 Figured it out. It was due to mismatch in the names of the columns. My dataframe has columns A and B but my table has columns C and B. Modified the columns to match the names and then it worked.

View solution in original post

1 REPLY 1
karun_r
Microsoft Employee
Microsoft Employee

 Figured it out. It was due to mismatch in the names of the columns. My dataframe has columns A and B but my table has columns C and B. Modified the columns to match the names and then it worked.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.