Click here to Skip to main content
12,395,871 members (65,002 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
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 30-Jan-13 0:28am
Rate this: bad
 
good
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.
  Permalink  
Rate this: bad
 
good
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.
  Permalink  

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 | Mobile
Web01 | 2.8.160721.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2016
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