DataGrid sometimes, you need to display the ordinal number of each row in the DataGrid, and if you use an Oracle database, you can use rownum to construct the row ordinal in the Select command and then bind directly to the DataGrid, but if you are using a SQL Server database, So, how do you add a row number to the DataGrid?
Ado. NET supports AutoIncrement columns through the DataColumn 3 properties: Autoincrement,autoincrementseed,autoincrementstep. You can generate AutoIncrement values for new rows of a DataTable as long as you set the DataColumn AutoIncrement to True. Look at an example:
The above OrderID column is set to AutoIncrement, note that the next two sentences, the value is set to 1, which has a certain reason. AutoIncrementSeed and AutoIncrementStep control how the new values are generated. When an empty table is encountered, Ado.net assigns values stored in AutoIncrementSeed to the first row of AutoIncrement columns, followed by AutoIncrementStep generation of subsequent autoincrement values.
Cause: The AutoIncrement value generated in ado.net is just a placeholder, generating a real new value in the database, showing only the new line AutoIncrement values that are not submitted to the database, and the database may generate different values based on the generated values. Both AutoIncrementSeed and AutoIncrementStep are set to-1 to ensure that the generated placeholder values do not appear in the database.
So in the use of AutoIncrement should be autoincrementseed and AutoIncrementStep are set to-1.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.