Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted
You would have to do that manually. I can't help but wonder why though - why are you doing this?

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

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.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

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

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...