Saturday, October 14, 2006

Import Excel To Datagrid

private void btnImportExcelToGrid_Click(object sender,
System.EventArgs e)
String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Book2.xls;" +
"Extended Properties=Excel 8.0;";

DataSet ds = new DataSet();
//You must use the $ after the object
//you reference in the spreadsheet
OleDbDataAdapter da = new OleDbDataAdapter
("SELECT * FROM [Sheet1$]", strConn);

//da.TableMappings.Add("Table", "ExcelTest");

DataGrid2.DataSource = ds.Tables[0].DefaultView;

Note: If you want to give client upload facility, than first upload the file to the server. Next call the excel file from the following server location. Reference:


Unknown said...


Here you can find the fast and easy way to import or export DataGrid to XLS, XLSX, HTML or CSV files by using GemBox.Spreadsheet .NET component:

Here you can find free version of the component that you can use even in commercial applications:


Kedar said...

I saw the component and have limitation as below

Maximum number of rows per sheet is 150.
Maximum number of sheets per workbook is 5.

Sudha said...


I want to import the excel which has 6 tabs.i want to import the data into 6 different gridviews. Each tab contains more than 1000 records. without affecting the performance how to achieve this?

Please help me.


Prateek Shukla said...

I've been searching such a easy code for a long time

Most Recent Post

Community Updates

Subscribe Blog via Email

Enter your email address:

Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape