Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
0 CPallini 385
1 Sergey Alexandrovich Kryukov 262
2 OriginalGriff 200
3 George Jonsson 134
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,890
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
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