Search code examples
c#oledbxlsx

C# - Reading .xlsx file failed returning ISAM error message


I'm trying to access a .xlsx file which I want to read and I'm doing it like that :

protected void btnImportList_Click(object sender, EventArgs e) {

    string connnection = @"Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:\Users\Karl\Desktop\NESR data\Autoload Sample - Goals.xlsx;Extended Properties=\Excel 12.0 xml;HDR=YES;IMEX=1\;";
    OleDbConnection con = new OleDbConnection(connnection);
    OleDbCommand command = new OleDbCommand();

    DataTable dt = new DataTable();
    OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [DL JV + VS Final$]", con);

    myCommand.Fill(dt);
    Console.Write(dt.Rows.Count);   
}

However, I'm getting the following error message :

Could not find installable ISAM

I installed the Microsoft AccessDatabase Manager as it was said on the internet but I'm still trying to figure out what more I can do to fix that. Any idea?


Solution

  • Use the below connection string,

    string connnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Karl\Desktop\NESR data\Autoload Sample - Goals.xlsx; Extended Properties=Excel 12.0;"
    

    There should be a space between 'Data' and 'Source' and removed HDR=YES, IMEX=1.