Reading Excel File

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

I'm having a problem reading data from an Excel file into a dataset. Can
anybody give me an idea of what's happening? I've included the problematic
source and the error message to the end of this message.

TIA

Brad


Here's a snippet of my source code:
//Retrieve data from the Excel spreadsheet file

string myConnectionString;

OleDbConnection myConnection;

OleDbDataAdapter myAdapter;

DataSet myDataSet = new DataSet("XLS");

myConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=" +

FileName + ";Extended Properties=Excel 8.0;HDR=Yes;IMEX=1";

myConnection = new OleDbConnection(myConnectionString);

myAdapter = new OleDbDataAdapter("select * from [Dataset$]", myConnection);

myAdapter.Fill(myDataSet);

myConnection.Close();

return (myDataSet);

}

Here's the Error Message:
"System.Data.OleDb.OleDbException: Could not find installable ISAM.\r\n at
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString
constr, OleDbConnection connection)\r\n at
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection
owningObject)\r\n at
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection
owningConnection, DbConnectionPoolGroup poolGroup)\r\n at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)\r\n at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)\r\n at
System.Data.OleDb.OleDbConnection.Open()\r\n at
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[]
datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand
command, CommandBehavior behavior)\r\n at System.Data.Common.DbDataAdapte

r.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior)\r\n at
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)\r\n at
RD.DBLoad.ERD.CoSo.MeterData.Read() in
F:\\Projects\\DbLoad_Solution\\RD.DBLoad.ERD\\ERD\\CoSo\\MeterData.cs:line
90"
 
I'd say you want something like this


select * from [Sheet1]

Its the name of the SHEET (bottom left) when you have the excel file open in
the program Microsoft Excel.

Its not the name of the DataSet.
 
That was exactly my problem! Thanks for saving me the time on google!

Brad


Tasos Vogiatzoglou said:
Check this :
http://blogs.wdevs.com/Gaurang/archive/2005/06/15/5112.aspx

I'm having a problem reading data from an Excel file into a dataset. Can
anybody give me an idea of what's happening? I've included the
problematic
source and the error message to the end of this message.

TIA

Brad


Here's a snippet of my source code:
//Retrieve data from the Excel spreadsheet file

string myConnectionString;

OleDbConnection myConnection;

OleDbDataAdapter myAdapter;

DataSet myDataSet = new DataSet("XLS");

myConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=" +

FileName + ";Extended Properties=Excel 8.0;HDR=Yes;IMEX=1";

myConnection = new OleDbConnection(myConnectionString);

myAdapter = new OleDbDataAdapter("select * from [Dataset$]",
myConnection);

myAdapter.Fill(myDataSet);

myConnection.Close();

return (myDataSet);

}

Here's the Error Message:
"System.Data.OleDb.OleDbException: Could not find installable ISAM.\r\n
at
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString
constr, OleDbConnection connection)\r\n at
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool,
DbConnection
owningObject)\r\n at
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection
owningConnection, DbConnectionPoolGroup poolGroup)\r\n at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)\r\n at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)\r\n at
System.Data.OleDb.OleDbConnection.Open()\r\n at
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[]
datatables, Int32 startRecord, Int32 maxRecords, String srcTable,
IDbCommand
command, CommandBehavior behavior)\r\n at System.Data.Common.DbDataAdapte

r.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior)\r\n at
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)\r\n at
RD.DBLoad.ERD.CoSo.MeterData.Read() in
F:\\Projects\\DbLoad_Solution\\RD.DBLoad.ERD\\ERD\\CoSo\\MeterData.cs:line
90"
 
Back
Top