0

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?

3
  • Could you show your connection string? Do you use HDR=YES? Commented Oct 10, 2012 at 7:55
  • Hi, thanks for suggestion. I changed it to 'HDR=YES' and used second answer ([Status]) and it worked. Commented Oct 10, 2012 at 9:05
  • But it is necessary to put the square brackets after the HDR=YES? Commented Oct 10, 2012 at 9:07

1 Answer 1

3

escape the column status

var sql = "Update [Sheet2$] set [Status] = 'New_value' WHERE Building = 12";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.