Reputation: 1579
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
Reputation: 1579
Found the solution in this thread:
Based on the information provided in that thread this occurs because I'm using a DataSet and a DataAdapter in my application.
Upvotes: 0
Reputation: 6130
Check this site below:
Is there any autoincrement type in SQL server CE?
How to enable auto-increment with Sql compact & C#
Upvotes: 1
Reputation: 94645
Edit your table schema and set Identity Increment = 1
and Identity Seed = 1
properties of identity
column.
Upvotes: 3