I have a few for example insert new records, when the store must have "SET IDENTITY_INSERT TabeleName ON"; and "SET IDENTITY_INSERT TabeleName OFF"; other examples do not need 2 lines ON and OFF, if I wanted to give my 2 lines to adjust what ? you see the code below:
strSQL = "SET IDENTITY_INSERT TabUsername ON ";
strSQL = strSQL + "INSERT INTO TabUsername(USERNAME";
strSQL = ...
strSQL = strSQL + "SET IDENTITY_INSERT TabUsername OFF";
...
SqlCommand cmd = new SqlCommand(strSQL,cnn);
try
{
cmd.ExecuteNonQuery();
cnn.Close();
}
....
Loading

Ahmar HusainRank #1,312 · 1.3K reputationPosted Jun 10, 2014, 9:03 PM EDT
Dong Lam TrienRank #1,538 · 1K reputationPosted Jun 11, 2014, 6:38 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 11, 2014, 8:54 PM EDT
hi,
Auto identity column is used to generate auto number in column.you cannot insert the value into this column.
SQL server provide the way to insert the value into this column using SET IDENTITY_INSERT TabUsername ON / OFF statement.
Please refer
http://technet.microsoft.com/en-us/library/bb734402(v=sql.110).aspx
hope this will help you.