Search code examples
c#sqloledb

System.Data.OleDb.OleDbException: Syntax error in UPDATE statement


I have an excel file with 2 sheets and want update some values in 'Data' sheet. I use the next simple commands:

var myCommand = new OleDbCommand();
var sql = "Update [Sheet2$] set Status = 'New_value' WHERE Building = 12";
var myConnection = new OleDbConnection(connectionString);
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();

I get error:

System.Data.OleDb.OleDbException : Syntax error in UPDATE statement

I have also tried this:

var sql = "Update [Sheet2$] set Status = 'New_value' WHERE Building = '12'";

but with no success. What is wrong here?


Solution

  • escape the column status

    var sql = "Update [Sheet2$] set [Status] = 'New_value' WHERE Building = 12";