简体   繁体   中英

“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);
                }
            }
        }
    }
}

}

我可以通过将连接字符串修改为:

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' ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM