“Operation must use an updateable Query” error when updating Excel


Make sure that your connection string does not have “IMEX=1” in it.

private void UpdateEmailSent( string apexId ) {
            try {
                string excelConnectionString = string.Format( "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES\";", lmiUserFileTextBox.Text );
                System.Data.OleDb.OleDbConnection MyConnection;
                System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand( );
                string sql = null;
                MyConnection = new System.Data.OleDb.OleDbConnection( excelConnectionString );
                MyConnection.Open( );
                myCommand.Connection = MyConnection;
                sql = string.Format( "UPDATE [Sheet1$] SET [Email Sent] = 'X' WHERE [APEXID]='{0}'", apexId );
                myCommand.CommandText = sql;
                myCommand.ExecuteNonQuery( );
                MyConnection.Close( );
            } catch ( Exception ex ) {
                MessageBox.Show( ex.ToString( ) );

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s