954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# and mycrosoft sql server 2k8?

hi guys, im using microsoft c# along with sql server 2k8 to build my database software, i have 2 problems..

1st is i cant seem to make an incrementing primary key that doesnt start with 1?
i wanted to make my primary key start from 00001 then increment it by 1 but it only allows me to start from 1 and increment by 1.

2nd problem is, when i delete rows in my database using my c# program, it works but when i add new rows, it still remembers the primary key of the row i deleted then it skips the primary key and uses the next number..
Example if this is when i delete a row with primary key of 4. then add a new row, it automatically creates a row with primary key of 5 instead of 4. can i fix this? thanks

rubentan
Newbie Poster
3 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

If you have an auto incrementing number, you've just described exactly what it is supposed to do, it does not reuse numbers. If you want it to fill in the holes, then you would need to not use an auto increment, and do a routine that works out the holes in your numbers list to find which numbers it can put in.

As for the key being 000001, that comes down to formatting.

Neither of these is specific to c# or SQL 2008

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

Sivak, your post has nothing to do with this thread.

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

set identity seed to be able to change the 1 to a different number

the padding with 0's is formatting, do it code side or in query, not store numbers in a database like that

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You