Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
1.00/5 (1 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.
HTML
Excel column
------------
Emp_Id   
Emp_Name

HTML
Table Column
-------------
Emp_ID
Emp_Name

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
Updated 20-Sep-12 4:45am
v3

1 solution

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):

C#
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 )
   {
      SaveEmpData(emp);
   }
}</empdata>


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

Hope this helps.

Cheers.
 
Share this answer
 
Comments
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.
I.explore.code 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.
I.explore.code 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)



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