Click here to Skip to main content
12,955,891 members (66,315 online)
Rate this:
Please Sign up or sign in to vote.
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?
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 30-Jan-13 0:28am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,719
CHill60 3,550
Maciej Los 3,153
ppolymorphe 2,060
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2017
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