P
Peter Cushing via .NET 247
I've an Excel file that I've been trying to make editable by Webusers via ASP.NET - however I just can't make the update syntaxto work. It's not an ASP problem, I've copied the code into anWindows application, and it still generates a "Syntax error inupdate statement" exception. The excel file has two columns,one with "Key" in cell A1, the other with "Value" in cell "B1". Column A is defined to be "Key", column B is defined to be"Value". C
string excelDocPath2 ="C:\\inetpub\\wwwroot\\ExcelData1.xls";
System.Data.OleDb.OleDbConnection objConn= newSystem.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelDocPath2 + ";Extended Properties=\"Excel8.0;HDR=YES;\"");
objConn.Open();
OleDbCommand objCmdUpdate = new OleDbCommand("UPDATE [Sheet1$]SET Value = '40' WHERE Key = '2'");
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objCmdUpdate.Connection=objConn;
objAdapter1.InsertCommand = objCmdUpdate;
try
{
objCmdUpdate.ExecuteNonQuery();
}
finally
{
objConn.Close();
}
string excelDocPath2 ="C:\\inetpub\\wwwroot\\ExcelData1.xls";
System.Data.OleDb.OleDbConnection objConn= newSystem.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelDocPath2 + ";Extended Properties=\"Excel8.0;HDR=YES;\"");
objConn.Open();
OleDbCommand objCmdUpdate = new OleDbCommand("UPDATE [Sheet1$]SET Value = '40' WHERE Key = '2'");
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objCmdUpdate.Connection=objConn;
objAdapter1.InsertCommand = objCmdUpdate;
try
{
objCmdUpdate.ExecuteNonQuery();
}
finally
{
objConn.Close();
}