• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1225
  • Last Modified:

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

  • 2
1 Solution
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: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/eadf8e6b-c2ae-4b35-8b1d-ebead03bffb7
Link to data reader: http://exceldatareader.codeplex.com/Wikipage
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:


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now