locked
Decrement the identity column after deletion a record in SQL with C# RRS feed

  • Question

  • hello Sir! how we will Decrement the identity column after deletion a single record? this method reseed the identity value after deletion the whole table...but i need the code for decrementing an identity column after clicking once on deletion button... 

    Here is my Resed method....which is fully reseeding to 0 value after deletion the whole table....

    private void RESED()
            {
                SqlConnection con = new SqlConnection("Data Source=localhost\\sqlexpress;Initial Catalog=StudentDB;Integrated Security=True");
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandText = "DBCC CHECKIDENT ('Student_Table', RESEED, 0)";
                cmd.ExecuteNonQuery();
                con.Close();
            }

    • Moved by Bob Beauchemin Wednesday, November 18, 2015 5:49 PM Moved to the forum for client-side SqlClient for best results
    Wednesday, November 18, 2015 6:45 AM

Answers

All replies