I want to update three fields/columns in my database table. One of them is primary key “id”, I made it autoincrement using visual studio’s set column properties:
Identity Specification: Yes
(Is Identity) : Yes
Identity Seed : 1
Identity Increment : 1
Everything going ok, but after checking for 2 times that every thing is going fine I emptied the contents of the table so that the columns can be newly populated. But first row autoincrement column got the value 3. I deleted the row and tried again but It became 4 after row was updated. I don’t know what is happening. My linq code has nothing to do with it I suppose, because its just insertion.
Code behind linq:
//DLCountryies - .dbml filename
// tblcountry - tablename
// CountryName and CountryCode are Column names
//txtCountryName - textbox
using (DLCountryiesDataContext countries = new DLCountryiesDataContext())
{
tblcountry country = new tblcountry
{
CountryName = txtCountryName.Text.Trim(),
CountryCode = txtCountryCode.Text.Trim()
};
countries.tblcountries.InsertOnSubmit(country);
countries.SubmitChanges();
}
You’re actually seeing the proper behavior for auto-increment columns. The identity value isn’t determined by using the current values in the table. SQL Server tracks identity values elsewhere.
Those values don’t reset after deleting records. The column simply continues counting from the last value.