autoincrement

  • Thread starter Thread starter Herman Lammers
  • Start date Start date
H

Herman Lammers

Hi,

i have a weird problem with autoincrement fields in a SQL server table.
Here's what happens.

I have a table with a Primary Key Field Id (int) that is defined (in SQL
server) as an Identity Field with Identity Seed 1 and Identity Increment 1.

current id values in the table are :

1, 2, 3, 4, 5, 6, 7, 8, 9, 11

In my program i use a SqlDataAdapter to fill the local dataset. After doing
this i inserted the following code (to avoid concurrency problems, from
various KB articles):

dim dc as DataColumns = ds.tables("MyTable").Columns("Id")
with dc
.AutoIncrement = true
.AutoIncrementSeed = -1
.AutoIncrementStep = -1
end with

Surprisingly, when I add a new row to the table, (using the NewRow method
from the table object), the
Id field in the new row does not get the value -1 (as one would expect) but
the value 10 ?!?

I have tried to use FillSchema before the actual fill, or setting the
MissingSchemaAction of the dataadapter to AddWithKey, but no luck at all,
and now i'm stuck!

Does anyone have any ideas?

Thanks

Herman
 
Herman:

When does it register as 10, immediately when you add the row to the table?
That's pretty weird and I'm wondering if Update isn't being called and it
has the refresh dataset option enabled. Are you getting any sort of
exception when you call update like a PK violation?

Bill

www.devbuzz.com
www.knowdotnet.com
 
Back
Top