R
Roger Frei
Hello.
I'm trying to write to an Excel file via an OleDbConnection. It always fails
with the error "Operation must use an updateable query".
The Excel file is not read-only and the process has enough rights to write
data to the filesystem. Additionally, reading from the file is possible but
writing fails. This is the code:
(Additional information: C#/ASP.net 2/Office 2003)
string path = Server.MapPath("temp\\test.xls");
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
path + @";Extended Properties=""Excel 8.0;HDR=YES;""";
OleDbConnection objConn = new OleDbConnection(connectionString);
try {
objConn.Open();
OleDbCommand oCmd = new OleDbCommand("INSERT INTO [myWorkSheet$]
([orderId], [hours]) VALUES (1,2)", objConn);
int i = oCmd.ExecuteNonQuery();
Response.Write("<br>Updated rows: " + i);
} finally {
objConn.Close();
}
Please help. This f**** problem is driving me nuts! Should it generally be
possible to write to Excel files in this way?
Cheers Roger
I'm trying to write to an Excel file via an OleDbConnection. It always fails
with the error "Operation must use an updateable query".
The Excel file is not read-only and the process has enough rights to write
data to the filesystem. Additionally, reading from the file is possible but
writing fails. This is the code:
(Additional information: C#/ASP.net 2/Office 2003)
string path = Server.MapPath("temp\\test.xls");
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
path + @";Extended Properties=""Excel 8.0;HDR=YES;""";
OleDbConnection objConn = new OleDbConnection(connectionString);
try {
objConn.Open();
OleDbCommand oCmd = new OleDbCommand("INSERT INTO [myWorkSheet$]
([orderId], [hours]) VALUES (1,2)", objConn);
int i = oCmd.ExecuteNonQuery();
Response.Write("<br>Updated rows: " + i);
} finally {
objConn.Close();
}
Please help. This f**** problem is driving me nuts! Should it generally be
possible to write to Excel files in this way?
Cheers Roger