Re: DataSet auto increment problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Make sure that your update query is not trying to insert or update that
column. That's the only reason I can think of for it to do this to you.

Robin S.
---------------------------------------
"Mark" <Mark@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E6C29340-8ED2-485B-B36B-1E35858A095E@xxxxxxxxxxxxxxxx
Hi Everyone:
I have set up a dataset that uses an auto increment field that is set to
start at minus one and step by minus one when I add a new record to the
dataset.

Example dataset:
1. Existing Record 1
2. Existing Record 2
3. Existing Record 3
4. Existing Record 4
5. Existing Record 5

The ID field is an auto increment field in SQL Server. To prevent
accidental
data corruption, whenever I add a new record to the dataset I start
with -1.
So the dataset will look like this when I add new records:

1. Existing Record 1
2. Existing Record 2
3. Existing Record 3
4. Existing Record 4
5. Existing Record 5
-1. 1st New Record
-2. 2nd New Record
-3. 3rd New Record

Here is my problem when I try to save the new record into the dataset I
get
the following error:
"Constraint Exception was unhandled. Column 'ID' is constrained to be
unique. Value '4' is already present."

I don't understand why this is happening. The dataset's auto increment
field
should put a -1 on the new record I'm adding. Instead it looks like it is
starting at the last record '5', subtracts one to get four and is trying
to
place the new information in record four instead of creating a new record
in
the dataset and starting the ID number at -1.

What is going on?

Thank you,

--
Mark


.



Relevant Pages

  • Re: [PHP] Pragmatically changing a "Record Number"
    ... I asked on a MySQL list about "Resetting a auto increment filed" so ... The ID key field of a record should not have any explicit meaning. ... Which is what I have figured out from the people on this list, I have decided to not play with the auto increment field, but the need I'm looking for hasn't changed, just the method. ... but they should have told you on the MySQL ...
    (php.general)
  • Re: auto-increment
    ... No, I don't need more than one identity column, I just wanted to have two ... Apparently an auto increment column should also be ... inserting auto increment values but currently have a data set that I need to ... auto increment field. ...
    (microsoft.public.sqlserver.programming)
  • Re: Auto increment
    ... Sir I set inv_no (auto increment) in my table sir when ever I zap this ... and append it from backup table the field inv_no incremented sir how to ... programmatically set the initial value of auto increment field and how set ...
    (microsoft.public.fox.programmer.exchange)