-1

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: External table is not in the expected format.

private void button1_Click(object sender, System.EventArgs e)
    {
        string path = @"C:\Projects\test.xlsx";
        string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

        string sql = "SELECT * FROM [Sheet1$]";
        using (OleDbDataAdapter adaptor = new OleDbDataAdapter(sql, connStr))
        {
            DataSet ds = new DataSet();
            adaptor.Fill(ds);
        }
    }

adaptor.Fill(ds); ==> Additional information: External table is not in the expected format.

Ahmed Mohammed
  • 337
  • 3
  • 16

1 Answers1

1

This code is working, check if the file location is correct and also if the sheet name is Sheet1.

The code is tested on my local system and no exception are thrown.

mybirthname
  • 17,949
  • 3
  • 31
  • 55
  • Additional information: The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data. this is the exception – Ahmed Mohammed Dec 07 '15 at 08:07
  • 1
    That means your excel file is already open, by your code or in the explorer. – mybirthname Dec 07 '15 at 08:14
  • 1
    I closed all open windows except visual studio, this exception is showen ( Additional information: External table is not in the expected format. ) – Ahmed Mohammed Dec 07 '15 at 08:38