Click here to Skip to main content
13,352,408 members (38,615 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have Excel sheet and have 1000 records are there, i want to verify duplicate id and name, before insertin in SQL Table, Please Help me.

If the record exists, then i will move to the next record and then insert.
Excel column

Table Column

Emp_Id Should check the duplication from the excel and then insert. if duplication founds then it should check and insert the next rows.

How to do this..?
Posted 20-Sep-12 4:57am
Updated 20-Sep-12 5:45am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Assuming you have read the data from the file into some sort of collection say List<empdata>, where EmpData is your object here is what I would do (in almost pseudocode):

List<empdata> emps = ParseExcelData();
foreach(EmpData emp in emps)
   //if this emp doesn't exist in the DB already, the function would return null
   //but if its not null, then it will just skip and move to next record repeating    the same process
   if (GetEmpDataFromDatabaseById(emp.Emp_ID) == null )

You would have to write your own ParseExcelData, GetEmpDataFromDatabaseById and SaveEmpData methods.

Hope this helps.

gani7787 26-Sep-12 2:05am
Can anyone give exact code or answers which is related to my questions.?
My Question is : before uploading bulk data to excel, i eant to check the duplication.
if duplication exists then it should insert the next record.

i am struggling last two weeks regarding this issue. pls. help.
gladiatron 26-Sep-12 2:56am
What do u mean "before uploading bulk data to excel"? I thought u wanted to insert into SQL table.
gani7787 1-Oct-12 9:08am
Yes. i wanted to insert bulk excel data into SQL table. before uploading it should check the duplication values from excel.
gladiatron 1-Oct-12 9:36am
yeah so for every record, before you store into database you check if it already exists in the DB i.e. if this record was seen before from the file. If the DB has that record that means the program has seen this record before which implies that the Excel file has a duplicate.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100