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
Jignesh TrivediPosted Jun 12, 2014, 12:54 AM
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.
Dong Lam TrienPosted Jun 11, 2014, 10:38 PM
Ahmar HusainPosted Jun 11, 2014, 1:03 AM