I am getting an syntax error when I am trying to write to a excel file using ADO.NET. How can i add parameters to the query. I am updating a mysql database.
string error="Text for status";
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=Excel 12.0;";
System.Data.OleDb.OleDbConnection ExcelConnection = new System.Data.OleDb.OleDbConnection(connectionString);
string ExcelQuery;
ExcelQuery = "Update [Sheet1$] set Status="+error; // from Sheet1";
//Create the command to be executed
ExcelCommand = new System.Data.OleDb.OleDbCommand(ExcelQuery, ExcelConnection);
//Open the connection to the file
ExcelConnection.Open();
//Execute the update
ExcelCommand.ExecuteNonQuery();
//Close the connection
ExcelConnection.Close();
Syntax error (missing operator) in query expression ‘Text for the
status’.
You can use the OleDbCommand.Parameters.Add for adding parameters to the Command.