Read Excel using Dotnet application

steps:

1) create simple dotnet application(here i am used C#.net)

2) put the below code

//add namespace
using System.Data.OleDb;
//read Excel File
string FilePath =”c:\test.xls”;
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ FilePath +";Extended Properties=Excel 8.0");
OleDbDataAdapter da = new OleDbDataAdapter("select * from [sheet1$]", con);
DataTable dt = new DataTable();
//get data in datatable
da.Fill(dt);
Thnx
 
Advertisements

2 comments

  1. i faced here some problem Like : –

    External table is not in the expected format

    actually my req. is system generate xls file n then user will update some col.

    then again nedd to import in DB .. at that time i face above error : External table is not in the expected format.

    i hope u will reply for suggestion…

  2. thanks for providing the simple example for reading excel files

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s