Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day all, I am having little issue removing duplicate record
First I want to be able to compare the record from excel to that of the SQL, if the same, one will be deleted.. How do i please achieve that below is the code on how to import to sql using linq
C#
            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;
            }

Thank you very much.. I really do appreciate your time and effort.
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900