vellaima Posted March 4, 2003 Posted March 4, 2003 I have created a DataTable with a Serial No Column. In this Column I am using AutoIncrementSeed. When I delete a row in the DataTable I would like to re-number it again. DataTable : MyTable S.No Items 1 Item A 2 Item B 3 Item C In the above scenario, if i delete Item B it should be re-numbered as follows. DataTable : MyTable S.No Items 1 Item A 2 Item C. Is it possible in VB.NET? Could you please help me out? Quote
TechnoTone Posted March 4, 2003 Posted March 4, 2003 You would have to do that manually. I can't help but wonder why though - why are you doing this? Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
vellaima Posted March 4, 2003 Author Posted March 4, 2003 How can it be done manually? Can anyone please give me a solution for this problem? Quote
TechnoTone Posted March 4, 2003 Posted March 4, 2003 Sorry - I should've been more informative. You can't to it with an AutoIncrementSeed column. You'll have to have a basic numeric column to hold the sequence number. Then, when you want to re-set the sequence you'll have to open a recordset and run through each record assigning a new sequence number. I would still like to know why? There must be a better way to do what you require. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
TechnoTone Posted March 4, 2003 Posted March 4, 2003 It's just occurred to me that you could use a query - if your serial number is a numeric (sorry - I'm a bit slow today :)). If you delete item with serial number X then run a query to modify all items with a serial number >X and set it to the current value minus 1. Something like this, assuming you've just deleted item with serial number 5: UPDATE mytable SET mycolumn = mycolumn-1 WHERE mycolumn > 5 Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
*Experts* Nerseus Posted March 4, 2003 *Experts* Posted March 4, 2003 If you plan on saving this data to a DataBase as an Identity column you shouldn't have to worry - the number in the DataBase will override whatever is in the DataSet. So even though you show "1" and "3" the database may substitute "467" and "468". If you are using the AutoIncrement as a pure sequence for the current data only, then you shouldn't use AutoIncrement but use TechnoTone's advice and make it a regular number. You'll have to manually change the number as rows are added/deleted. During a Delete of a DataRow, you'll have to grab the current value, loop through all rows that are higher numbered and decrement their number by one. Well, that's one way to do it anyway. The point is that you'll have to do it manually :) I'm not sure what TechnoTone means with the "UPDATE myTable..." since I don't know how you'd execute this "query" against a DataSet. If you had already saved it to a database, maybe - but I'd think you'd want to change it before it got saved to the DB. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
vellaima Posted March 4, 2003 Author Posted March 4, 2003 I am doing as TechoTone has suggested. Looping thro' manually using regular number. Thanks for the help provided. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.