ADO.NET supports automatic incrementum columns through the 3 properties of Datacolumn: AutoInCrement, AutoInCrementSeed, AutoInCrementsTep. Just set the DataColumn's AutoInCrement to True, you can generate an automatic incremental value for the new line of DataTable. Watch an example:
DataSet DS
=
New
DataSet (); DataTable DT
=
DS.Tables.Add (
"
ORDERS
"
DataColumn col
=
Dt.column.add (
"
ORDERID
"
,
Typeof
(
int
); col.autoincrement
=
True
; col.autoincrementseed
= -
1
COL.AUTOINCREMENTSTEP
= -
1
COL.READONLY
=
True
;
The above ORDERID column is set to automatic increment, pay attention to the next two sentences, and its value is set to -1, where there is a reason. AutoInCrementSeed and AutoInCrementsTEP control how to generate new values. When you encounter a holiday, ADO.NET will assure the value stored in AutoInCrementSe to the first line of auto-increment columns, followed by autocrementStep to generate subsequent automated incremental values.
Cause: The auto-incremental value generated in ADO.NET is just a placeholder, which generates a real new value in the database, which is displayed simply not submitted to the database automatic increment value, the database may be based on The resulting value generates a different value. All AutoInCrementSeed and AutoInCrementsTep are all set to -1, ensuring that the generated placeholder value does not appear in the database.
So you should set alloincrementseed and autocrementstep to -1 when using AutoInCrement.