By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

[C#] problem with auto number in datatable

P: 5
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
Feb 27 '09 #1
Share this Question
Share on Google+
8 Replies


P: 5
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
Feb 27 '09 #2

Plater
Expert 5K+
P: 7,872
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.
Feb 27 '09 #3

P: 5
@Plater
Thanks for yoru reply .but how do number myself since the data is generated dynamically.
Feb 27 '09 #4

Plater
Expert 5K+
P: 7,872
Loop through the rows and assign the number to a spare column?
Feb 27 '09 #5

P: 5
@Plater
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
Feb 28 '09 #6

kunal pawar
100+
P: 297
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
Mar 2 '09 #7

P: 5
@kunal pawar
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
Mar 2 '09 #8

Plater
Expert 5K+
P: 7,872
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
Mar 2 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.