AutoIncrement DataColumn

  • Thread starter Thread starter Gerry Viator
  • Start date Start date
G

Gerry Viator

Hi,

Using AutoIncrement property on a Datacolumn and viewing in Datagrid
The first column in the datagrid shows the Incremented number.
This is all on the client side, just showing data, not bound to any data
from a database.

I have set it to true and to increment by one. Ok that works fine.
Now I have rows that I want to delete. That also works fine.
Ok, how do I reset the Increment of only counting whats there not totaly
whats been added?

Thanks for your help
Gerry
 
Hi Gerry:
Gerry Viator said:
Hi,

Using AutoIncrement property on a Datacolumn and viewing in Datagrid
The first column in the datagrid shows the Incremented number.
This is all on the client side, just showing data, not bound to any data
from a database.

First off, be careful here, b/c if you are using positive numbers, running
multiple instances of the app can get you in trouble. Say that two
instnaces start and we both start with the number 200. We both add two
records that are completely different and you submit yours first. It will
probably work fine and now the db will have records 201 and 202. Now I try
adding mine, but I have records 201 and 202 which will cause a collision.
You can assign each session a block of variables, like you'd start out at
200, I'd start out at 400, but this is very sloppy and leaves a lot of gaps
and records that should be successive might appear all over the place.

One easy solution is the set the autoincrement value to -1 and the seed to
0. This way, the value will always be negative for both of us. So our local
values each would be -1 and -2 in my example. WHen the update is submitted,
the DB will find the next legit value siunce it doesn't accept negative
values so your values would be 201 and 202 in the db. Now I submit mine and
it finds the next value...203. Then it finds the next value for my last
record 204. Viola!
I have set it to true and to increment by one. Ok that works fine.
Now I have rows that I want to delete. That also works fine.
Ok, how do I reset the Increment of only counting whats there not totaly
whats been added?

I'm not sure I follow you here but you can set the AutoIncrementSeed
property. This will dictate the beginning number of where the next value
will start. So in our example, if we were at 204 now, and I reset the seed
to 0, the next record inserted would have a value of 1. This would probably
blow up b/c we'd probably have a 1 already in the DB. I can't tell if you
are asking about the seed or how to renumber the sequence, if it's the
former, setting the AutoINcrementSeed property will do it. If it's the
latter, it depends on the DB you are using..if you tell me the back end
though, I can probably help you resequence it.

If I totally misunderstood your question though, please let me know and I'll
take another try.

Cheers,

Bill
 
Thanks for your help,

I guess I didn't explain it good enough.

No database!!!!! No dataset!!!! at this point.

Just local string variables stored in a datatable that is shown in a
datagrid. (The DataTable is bound to the datagrid)
I'm showing the increment numbers in the first Column of the datagrid of the
datatable. I delete rows of the
datatable and want to start the increment over again so the number are
correctly shown.

thanks and I hope I gave you more information

Gerry
 
Then just set the AutoIncrementSeed to the number you want counting to start
at. SO you have 100 rows for instance, and the number is 100. You delete
all of them, then set the seed to 0. If you deleted 20 of them, set the
seed to 81 (assuming you deleted contiguous blocks). If you are deleting
them randomly and you basically need everything resequenced, drop the
datacolumn, recreate it and set the autoincrement to true and the seed to 0.
This is bulky but it's the only way I know of to resequence it after the
fact.

HTH,

Bill
 
thanks
Gerry


William Ryan eMVP said:
Then just set the AutoIncrementSeed to the number you want counting to start
at. SO you have 100 rows for instance, and the number is 100. You delete
all of them, then set the seed to 0. If you deleted 20 of them, set the
seed to 81 (assuming you deleted contiguous blocks). If you are deleting
them randomly and you basically need everything resequenced, drop the
datacolumn, recreate it and set the autoincrement to true and the seed to 0.
This is bulky but it's the only way I know of to resequence it after the
fact.

HTH,

Bill
seed
 
Back
Top