Sometimes you need to display the serial number of each row in the DataGrid, if you use the Oracle database, you can use ROWNU to construct a row serial number in the select command, then bind to the DataGrid, but if you use the SQL Server database, then How to add row serial numbers to DataGrid? ADO.NET with 3 attributes of Datacolumn to support Auto Incrementum: 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.columns.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.
Author: Wu original: http: //blog.9cbs.net/zhpsam109/archive/2004/09/07/97326.aspx