public ActionResult UploadDataToSql() { CustomerAccount account = new CustomerAccount(); string fileName = @"C:\Users\MR Right\Desktop\Customers.xlsx"; var excel = new ExcelQueryFactory(fileName); var dataContent = from c in excel.Worksheet<CustomerSheet>("Customers") select c; excel.AddMapping<CustomerSheet>(x => x.ID, account.SFId); excel.AddMapping<CustomerSheet>(x => x.Name, account.AccountName); excel.AddMapping<CustomerSheet>(x => x.BillingStreet, account.StreetAddress1); excel.AddMapping<CustomerSheet>(x => x.BillingState, account.State.ToString()); excel.AddMapping<CustomerSheet>(x => x.BillingPostal, account.ZipCode); excel.AddMapping<CustomerSheet>(x => x.Phone, account.Country); excel.AddMapping<CustomerSheet>(x => x.CreatedDate, account.CreatedDate.ToString()); excel.AddMapping<CustomerSheet>(x => x.LastModifiedDate, account.LastModifiedDate.ToString()); //Checking the datacontent before accessing if (dataContent != null) { //reading content from the excel comes here foreach (var a in dataContent) { //all logics and save to database } } return View("~/Views/Admin/UploadData.cshtml"); }
foreach (var a in dataContent)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)