Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Negative "Primary Keys" show up when openning an SQL Server 2008 database in a Visual basic program.

Posted on 2010-09-20
8
Medium Priority
?
724 Views
Last Modified: 2013-11-26
Why am I getting Negative primary Keys?  The primary key field is set with Identity Spec (Yes). Is Identity (Yes). Identity increment (3), not -3. Identity seed 866731. I am using a data Grid from the table set.  
0
Comment
Question by:jampost
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720725
you see identity while you adding new data?or after update?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720726
i mean negative identity...
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720755
It could happen..and it is logic...http://blog.sqlauthority.com/2010/08/19/sql-server-negative-identity-seed-value-and-negative-increment-interval/
"Negative identity values are useful in programming: if you have build part of your database in memory as a dataset and you want to submit the changes back to the server, you cannot be sure of the identity values it will assign (especially in a shared environment). Therefore it is common to use negative identities and increments for the memory dataset and positive ones for the server database. The server does understands that mechanism and will assign correct values (It will take some tricks to refresh these values into the memeory dataset)."
For a more elaborate artikel see: Managing an @@Identity crisis at http://msdn.microsoft.com/en-us/library/ms971502.aspx
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:jampost
ID: 33721540
jtoutou,
    Thank you for your quick responce. The negative PKs are there before I enter the first record in the dataset. The database & table were all created in the SQL Server Management Studio. The data will be entered through a visual basic program, and that is were the negatives are showing up. I have to admit; I am not a level two or above programer. I assume you are telling me that this is normal. The problem I have is that this is a GUI. There would be no problem if this were behind the scenes. So I guess I need some specificities to correct this.
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 2000 total points
ID: 33722162
As far as i know You do not have to correct anything..."if you have build part of your database in memory as a dataset and you want to submit the changes back to the server, you cannot be sure of the identity values it will assign (especially in a shared environment)"
0
 

Author Comment

by:jampost
ID: 33730426
Jtoutou,
       
          Thank you. I probably need to get acquainted with the world of SQL. This is what I found out. First off you were very helpful in what you told me. I test by clearing all records and starting fresh. Going through the Data Set (The program I am developing in Visual Basic) Row one “Primary Key (“Customer Number” field heading),  I get -1 as the primary key. But…….When I open SQL Server 2008 and check the results in the table it has the test seed I planted (866731).  Now here is the head scratcher (to me anyway). I go back into Visual Studio and Start Debugging (running) the program and (NOW) it has 866731 in place of -1. I suppose it just needed to get refreshed.  Thank you, and I hope you will see my future questions. You have an A grade and 500 points.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33731798
hi....
very glad i helped you...


P.S You have to accept a solution if you got your answer...:)

0
 

Author Comment

by:jampost
ID: 33735428
I thought I accepted the solution yesterday. It is sort of like the debit card machine at check out. You start to walk away and it has one more yes box to click.  I think I got it this time. Thanks again
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question