Click here to Skip to main content
14,699,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my C# project I want to upload excelsheet and store it in DB. But in sql i set primary key for one field.. so if i upload 10 datas  including  duplicate values,  its rejecting whole sheet. i need to upload all data's except primary key  field. how can i?

<b>eg:</b>
Fields like Application no, Request type, Request name
i set primary key for Application no,

Excel sheet datas:

1.  1234 RiskEnvission  LSB
2.  4567 RiskEnvission  DES
3.  7865 RiskEnvission  LSB
//4.  1234 RiskEnvission  DES(except this field i need to upload above 3 data's)
Posted

1) check you PK col is auto increment column or not
2) If it is not auto increment column then in inserting query it self you do one thing you take maximum value of that column and then increment that column then pass that column value to inserting query , don't pass the PK value as a column.
   
You can't "upload all data's except primary key field." - the primary key is the one field that a record can never lack.
Don't make the Application number a primary key if there is a chance it will be duplicated - that is not permitted.
If you want multiple Application numbers, then add another field (an ID Field) and set that as the primary key.
   

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