How to: Reset value of autoincrement column, after delete the datarow?
-
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.
-
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.
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]
-
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.
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
-
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.