Connecting Tech Pros Worldwide Forums | Help | Site Map

[C#] problem with auto number in datatable

Newbie
 
Join Date: Feb 2009
Posts: 5
#1: Feb 27 '09
Dear All,

I having a datatable with the auto number, I need to know that how to restart/recalculate the auto number when a particular row being removed for example :
I have 5 row of record 1,2,3,4,5
When the row 2 being removed. i wanted it to show 1,2,3,4 instead of 1,3,4,5

Thank for helping

Newbie
 
Join Date: Feb 2009
Posts: 5
#2: Feb 27 '09

re: [C#] problem with auto number in datatable


Dear All,

I having a datatable with the auto number, I need to know that how to restart/recalculate the auto number when a particular row being removed for example :
I have 5 row of record 1,2,3,4,5
When the row 2 being removed. i wanted it to show 1,2,3,4 instead of 1,3,4,5

Thank for helping
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#3: Feb 27 '09

re: [C#] problem with auto number in datatable


Hide the autonumber column and number them yourself?
You cannot manually enter values in the autonumber column of a table.
If you delete one, you're stuck with a gap.
Newbie
 
Join Date: Feb 2009
Posts: 5
#4: Feb 27 '09

re: [C#] problem with auto number in datatable


Quote:

Originally Posted by Plater View Post

Hide the autonumber column and number them yourself?
You cannot manually enter values in the autonumber column of a table.
If you delete one, you're stuck with a gap.

Thanks for yoru reply .but how do number myself since the data is generated dynamically.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#5: Feb 27 '09

re: [C#] problem with auto number in datatable


Loop through the rows and assign the number to a spare column?
Newbie
 
Join Date: Feb 2009
Posts: 5
#6: Feb 28 '09

re: [C#] problem with auto number in datatable


Quote:

Originally Posted by Plater View Post

Loop through the rows and assign the number to a spare column?

I don't know how to do it with the suggestion stated by you.

actaully my datatable is use to store shopping cart item.So the autonumber column is create/updated when one item added in.However when the user removed item from the cart the autonumber column become weird as i stated ealier
kunal pawar's Avatar
Needs Regular Fix
 
Join Date: Oct 2007
Location: Pune, India
Posts: 297
#7: Mar 2 '09

re: [C#] problem with auto number in datatable


In database thats not posible, Either you have to use number in place of auto number fieled and put next numbers by useing code or trucate all records and again save records newly
Newbie
 
Join Date: Feb 2009
Posts: 5
#8: Mar 2 '09

re: [C#] problem with auto number in datatable


Quote:

Originally Posted by kunal pawar View Post

In database thats not posible, Either you have to use number in place of auto number fieled and put next numbers by useing code or trucate all records and again save records newly

Thank for your reply . One thing I need to make it clear. what I try to do with auto number is on datatable is not on database.


I aleready solved the problem by trasnfer it to another temporary datatable
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#9: Mar 2 '09

re: [C#] problem with auto number in datatable


If you make a spare column in your in your set of data, you can loop through the rows and assign a counter index to each of, for display purposes only
Reply

Tags
autonumber, c# asp.net, datatable