Search code examples
c#excelisam

"Cannot find installable ISAM" error when trying to pull data into C#


I'm currently working on an import from excel to c#, but this is the first time doing so, I thought I had the connection working after solving a number of other issues, but I am now receiving the above error.

The code builds absolutely fine, and I can't find any other issues, anyone have any ideas?

using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test_excel
{
class Program
{
    static void Main(string[] args)
    {
        // @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;';"
        string con =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Users\Joshua.cameron\Documents\BullenGrosvenorTest\EstatesITExportSpec.xlsx';Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;';";
// @"Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'";
        using (OleDbConnection connection = new OleDbConnection(con))
        {
            connection.Open();
            OleDbCommand command = new OleDbCommand("select * from [Rental Sheet$]", connection);
            using (OleDbDataReader dr = command.ExecuteReader())
            {
                while (dr.Read())
                {
                    var row1ColA = dr[0];
                    Console.WriteLine(row1ColA);
                }
            }
        }
    }
}

}


Solution

  • I was able to get this to work by modifying the connection string to:

    string con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Joshua.cameron\Documents\BullenGrosvenorTest\EstatesITExportSpec.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES' ";