Saturday, March 28, 2015

How do I write to specific cells in Excel? ... C#, OleDb


SET is not used in an INSERT statement. Try this:



string sql = "Insert into [" + stSheetName + "$A2:B2] VALUES('5','e')";



You could also use an UPDATE statement to update a specific cell:



string sql = "UPDATE [" + stSheetName + "$A2:A2] SET F1=5";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();

sql = "UPDATE [" + stSheetName + "$B2:B2] SET F1=e";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();



Both do not work ... exception: Cannot expand named range for the INSERT ... No value given for one or more required parameters for the UPDATE.



bhs67



No comments:

Post a Comment