DataSet auto increment problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
 
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.
 
Back
Top