Quirky Behavior with AutoIncrement

  • Thread starter Thread starter Swiftusw
  • Start date Start date
S

Swiftusw

I have a data set defined with a table that has an ID column with
AutoIncrement set to 'true'. The dataset was generated from a SQL data
adapter. If there is data in the table, then when I do
TABLE.NewTABLERow() the ID value increments fine and
DATASET.TABLE.IDCOLUMN.AutoIncrement = true. However, if the table is
empty then TABLE.NewTABLERow() results in an ID of 0 and
DATASET.TABLE.IDCOLUMN.AutoIncrement = false. Has anyone seen this
behavior and know of a workaround (other than putting seed data in the
database to force the AutoIncrement to act correctly).

Thanks,

Matt
 
Matt,
To avoid later collisions I always set my AutoIncrement columns
explicitly with
AutoIncrement = true
AutoIncrementSeed = -1
AutoIncrementStep = -1
This will then allow the database to generate the keys. Just make sure your
stored procedure feeds the new key value (from SCOPE_IDENTITY()) back to
you. Or, for Access, use a handler for the RowUpdated event to retrieve the
new key for the row.
See the help topic on Retrieving Identity or Autonumber Values

Ron Allen
 
Back
Top