user3340627
user3340627

Reputation: 3143

Select from Excel Sheet using OLEDB Adapter

I'm using the code below to access an Excel Sheet, but the adapter.Fill always throws an exception that the sheet could not be found.

string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\ImportSheet.xlsx;Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";";
  var adapter = new OleDbDataAdapter("SELECT * FROM [SheetName]", connectionString);
  var ds = new DataSet();
  adapter.Fill(ds, "anyNameHere");

I verified the path for the file and the sheetname, but i'm not sure why i keep getting this error. Would appreciate your help.

Upvotes: 0

Views: 1045

Answers (1)

user3340627
user3340627

Reputation: 3143

[SheetName$] add the dollar sign after the name of the sheet – Steve

Try "SELECT * FROM [SheetName$]" – danijepg

Upvotes: 1

Related Questions