Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to: Reset value of autoincrement column, after delete the datarow?

How to: Reset value of autoincrement column, after delete the datarow?

Scheduled Pinned Locked Moved Database
tutorialquestioncsharpvisual-studiohelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    krzychub
    wrote on last edited by
    #1

    Hi. I use VS 2005 and ADO.NET 2.0. The simplest example: I have DataSet with one DataTable ('Person') The 'Person' Table has 3 columns: 1.ID -> Autoincrement=True 2.LastName 3.FirstName On my form I have DataGridView Control and BindingNavigator. Using BindingNavigator's 'AddNewItem' button, I add new DataRow to my 'Person' Table then ID = 1 and i repeat this 3 times. After that I use BindingNavigator's 'DeleteItem' to remove last DataRow (ID = 3) from 'Person' Table. Now, when I add NewItem once again I have new DataRow with ID = 4. How can I reset this value back to '3' in autoincrement column? Somebody can help me, please? Thanks.

    C S K 3 Replies Last reply
    0
    • K krzychub

      Hi. I use VS 2005 and ADO.NET 2.0. The simplest example: I have DataSet with one DataTable ('Person') The 'Person' Table has 3 columns: 1.ID -> Autoincrement=True 2.LastName 3.FirstName On my form I have DataGridView Control and BindingNavigator. Using BindingNavigator's 'AddNewItem' button, I add new DataRow to my 'Person' Table then ID = 1 and i repeat this 3 times. After that I use BindingNavigator's 'DeleteItem' to remove last DataRow (ID = 3) from 'Person' Table. Now, when I add NewItem once again I have new DataRow with ID = 4. How can I reset this value back to '3' in autoincrement column? Somebody can help me, please? Thanks.

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      I have no idea how to accomplish this with either an Autoincrement property or using triggers with sequences. But I do know that since these types of columns are mostly used for primary keys, where the values typically have no relationship to the rest of the data in the row, what reason do you have for wanting some control on the next value after some delete operation has occurred. Consider as well, what happens when you delete where ID = 2; Should the next add do an insert with a value of 2 and then the next add use 4? Chris Meech I am Canadian. [heard in a local bar] When I want privacy, I'll close the bathroom door. [Stan Shannon] BAD DAY FOR: Friendly competition, as Ford Motor Co. declared the employee parking lot at its truck plant in Dearborn, Mich., off limits to vehicles built by rival companies. Workers have to drive a Ford to work, or park across the street. [CNNMoney.com] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]

      1 Reply Last reply
      0
      • K krzychub

        Hi. I use VS 2005 and ADO.NET 2.0. The simplest example: I have DataSet with one DataTable ('Person') The 'Person' Table has 3 columns: 1.ID -> Autoincrement=True 2.LastName 3.FirstName On my form I have DataGridView Control and BindingNavigator. Using BindingNavigator's 'AddNewItem' button, I add new DataRow to my 'Person' Table then ID = 1 and i repeat this 3 times. After that I use BindingNavigator's 'DeleteItem' to remove last DataRow (ID = 3) from 'Person' Table. Now, when I add NewItem once again I have new DataRow with ID = 4. How can I reset this value back to '3' in autoincrement column? Somebody can help me, please? Thanks.

        S Offline
        S Offline
        Steve Schaneville
        wrote on last edited by
        #3

        Typically you shouldn't need to set it back to '3' (and if you DO need to set it back, then there may be a fault in your design). It is common to have these "holes" in key/identity columns in databases. My recommendation would be don't worry about it... leave it as '4'. ~Steve www.roundpolygons.com

        1 Reply Last reply
        0
        • K krzychub

          Hi. I use VS 2005 and ADO.NET 2.0. The simplest example: I have DataSet with one DataTable ('Person') The 'Person' Table has 3 columns: 1.ID -> Autoincrement=True 2.LastName 3.FirstName On my form I have DataGridView Control and BindingNavigator. Using BindingNavigator's 'AddNewItem' button, I add new DataRow to my 'Person' Table then ID = 1 and i repeat this 3 times. After that I use BindingNavigator's 'DeleteItem' to remove last DataRow (ID = 3) from 'Person' Table. Now, when I add NewItem once again I have new DataRow with ID = 4. How can I reset this value back to '3' in autoincrement column? Somebody can help me, please? Thanks.

          K Offline
          K Offline
          krzychub
          wrote on last edited by
          #4

          Hi Guys. Thank you for all respondings. Answering to Steve's question: My only problem was, if I do everything OK (just out of sheer curiosity). Now I know that it's a problem which isn't open to discussion. Once again Thanks.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups