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?
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?
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();
}