How do I read an Excel file in .Net Compact Framework 2.0?


I'm developing a windows mobile 5.0 application that reads an excel file as a datatable. To do this in normal .net framework 2.0, I use the below code and there is no problem. What my problem is when using it in .net compact framework, there is no DbProviderFactory class ("System.Data.Common.DbProviderFactory" library does not exist).

Can anyone please help me reading this excel file in windows mobile please?

Thank you,
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\input.xls;Extended Properties=""Excel 8.0;HDR=NO;IMEX=1""";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbDataAdapter adapter = factory.CreateDataAdapter();
DbCommand selectCommand = factory.CreateCommand();
selectCommand.CommandText = "SELECT * FROM [Sheet1$]";
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionString;
selectCommand.Connection = connection;
adapter.SelectCommand = selectCommand;
DataSet table = new DataSet();
DataTable dtResult = table.Tables[0];

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

According to the MSDN forum you'll have to use the Codeplex Excel Data Reader, as no solution is included in the .NET compact framework.

Link to MSDN forum thread:
Link to data reader:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BTW: It's LGPLd, meaning you can link against it without having to make your code open source, so I believe it could be an acceptable solution for you.
Meir RivkinFull stack Software EngineerCommented:
there is no data provider or driver support for Excel (or Pocket Excel) running under the Compact Framework.
u can any 3rd party softwares which does that, like the following:

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.