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