当我尝试使用ADO.NET写入Excel文件时,出现语法错误。我如何添加参数到查询。我正在更新一个MySQL数据库。如何将参数添加到OleDbDataWriter
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();
语法错误(缺少操作员)在查询表达式 '文字的 状态'。
我正在使用字符串错误更新excel中的状态列。应该向它添加参数还是可以不使用参数执行 – Murthy