Read Excel In C#
Use below Namespaces:
using System.Data;
using System.Data.OleDb;
Add below code in Button click or where ever you required
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ExcelFilePath\Book1.xls;Extended Properties=Excel 8.0");
OleDbDataAdapter dataadp = new OleDbDataAdapter("select * from $sheet1", conn);
DataTable datatbl = new DataTable();
dataadp.Fill(datatbl);
using System.Data;
using System.Data.OleDb;
Add below code in Button click or where ever you required
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ExcelFilePath\Book1.xls;Extended Properties=Excel 8.0");
OleDbDataAdapter dataadp = new OleDbDataAdapter("select * from $sheet1", conn);
DataTable datatbl = new DataTable();
dataadp.Fill(datatbl);
0 comments: