Update Excel 2007 with OleDb
Attempting to execute an update command for an Excel 2007 file gives an error: The operation must use an updatable query. I am using System.Data.OleDb with a connection string like this:
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=""" & pathToFile & """;" & _
"Extended Properties=""Excel 12.0;HDR=YES"""
I've tried setting ReadOnly = false, but that gives Unable to find the ISAM to be installed. I also tried setting Mode = ReadWrite and IMEX = 1 which didn't seem to have any effect. My update command looks like this:
Dim cmd As OleDbCommand = con.CreateCommand()
cmd.CommandText = "UPDATE [" + sheetName + "] SET [Quantity Error] = 'test' WHERE [Full Name] = 'Mr. Brown White'"
where sheetName was obtained from excel schema request. Can I do what I am trying to do? Where did I go wrong?
Use this connection string, it will work
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + reportFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;\";
In addition to checking the permissions on the Excel file, check if the extended properties of the connection string contains an expression IMEX=1
. If so, remove it.
a source to share