try { string Pat = string.Concat(Server.MapPath("~/FileUpload/" + FileUpload1.FileName)); FileUpload1.SaveAs(Pat); string PathToExcelFile = Pat; var ExcelFile = new ExcelQueryFactory(PathToExcelFile); ExcelFile.AddMapping<Question>(x => x.QuestionOrder, "QuestionNo"); ExcelFile.AddMapping<Question>(x => x.Title, "Question"); ExcelFile.AddMapping<Question>(x => x.Answer1, "A"); ExcelFile.TrimSpaces = LinqToExcel.Query.TrimSpacesType.Both; ExcelFile.ReadOnly = true; IQueryable<Question> Quest = (from c in ExcelFile.Worksheet<Question>() select c); foreach (Question qu in Quest) { cdc.Questions.Add(qu); cdc.SaveChanges(); lblmess.Text = "Imported Successfully"; } } catch(Exception ex) { lblmess.Text = ex.Message; }
Import Excel data to sql table(replica of main table) then perform join with main table to select matched record.<br /> and truncate this Relica table every time when u upload excel file.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)