Pallas
Pallas

Reputation: 1579

How to make application auto-increment id in SQL Server Compact 3.5?

I've set up a SQL Server Compact 3.5 database in my WinForm application. I set my ID identity to true so that when the user adds to the database it will automatically give it an ID and automatically increment it. However, for some reason after the first item is entered into the database the ID goes to -1 and then -2, -3, etc. How come it doesn't increment correctly? Did I set it up incorrectly?

Update:

Another Update: I ran the application and added 4 things to the database, closed the application and opened it again. When I did this all the id's were suddenly correct. It's like the id is only incorrect when when it's first added, but when the database is reloaded it's correct. Hopefully that made sense.

Upvotes: 1

Views: 9460

Answers (3)

Pallas
Pallas

Reputation: 1579

Found the solution in this thread:

Negative Primary Keys

Based on the information provided in that thread this occurs because I'm using a DataSet and a DataAdapter in my application.

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94645

Edit your table schema and set Identity Increment = 1 and Identity Seed = 1 properties of identity column.

Upvotes: 3

Related Questions