-1

How can I read the excel sheet data in ASP.net without using OleDbConnection. I have tried OleDbConnection already but I am facing issues with it.

Are there any other ways to do so?

DG1209
  • 47
  • 2
  • 6
  • So shall we help to fix these issues with permissions or show an alternative way? You could use [`EPPlus`](http://epplus.codeplex.com/) or [`Open XML`](http://stackoverflow.com/questions/2624333/how-do-i-read-data-from-a-spreadsheet-using-the-openxml-format-sdk) – Tim Schmelter Dec 02 '15 at 09:37

3 Answers3

0

You need EPPlus for this kind of work. Site

Thanos Markou
  • 2,587
  • 3
  • 25
  • 32
0

Check this. It can read an excel file without OleDbConnection

rjps12
  • 587
  • 6
  • 15
0

you can use LinqToExcel to do this. following code will help a bit:

public ActionResult fileread()
{
     var excel = new ExcelQueryFactory(@"File Name");
     excel.AddMapping<ABC>(x => x.S1, "code");        // ABC is your database table name... code is the column name of excel file
     excel.AddMapping<ABC>(x => x.S2, "description");    
     // you can map as many columns you want    
     var e = (from c in excel.Worksheet<ABC>("MyExcelFile") select c); // MyExcelFile is the name of Excel File's Sheet name

// similarly you can do whatever you want with the data like.. save to DB
   foreach (var y in e)
   {
       ABC a = new ABC();
       a.S1 = y.S1;
       a.S2 = y.S2;
       db.ABC.Add(a);
   }
   db.SaveChanges();
}
Awais Mahmood
  • 1,308
  • 4
  • 21
  • 51