tailieunhanh - Retrieving New Identity Column Values

Retrieving New Identity Column Values The ProductID column of the Products table is an identity column. In this section, you'll see how to insert a new row into to Products table | Retrieving New Identity Column Values The ProductID column of the Products table is an identity column. In this section you ll see how to insert a new row into to Products table and retrieve the new value generated by the database for the ProductID identity column. Note You ll find a complete program named in the ch11 directory that illustrates the use of the methods shown in this section. This program listing is omitted from this book for brevity. In the examples assume you have a DataTable named productsDataTable that is populated with the rows retrieved by the following SELECT statement SELECT ProductID ProductName UnitPrice FROM Products ORDER BY ProductID The following example sets the PrimaryKey property of productsDataTable new DataColumn ProductID The next example sets the AllowDBNull AutoIncrement AutoIncrementSeed AutoIncrementStep ReadOnly and Unique properties for the ProductID DataColumn of productsDataTable DataColumn productIDDataColumn ProductID false true -1 -1 true true Because of these settings when you add a new DataRow to productsDataTable the ProductID DataColumn of your new DataRow will initially have the value -1. As in the earlier section Modifying Rows in a DataTable you need to set your DataAdapter object s InsertCommand UpdateCommand and DeleteCommand properties with appropriate Command objects. The CommandText property of the Command object used in the UpdateCommand property is as follows UPDATE Products SET ProductName @NewProductName UnitPrice @NewUnitPrice WHERE ProductID @OldProductID AND ProductName @OldProductName AND UnitPrice @OldUnitPrice The CommandText property of the Command object used in the .

TÀI LIỆU LIÊN QUAN
10    158    1
6    184    1
7    162    1
5    157    1
6    160    1
6    152    1
6    150    1
6    206    1
7    154    1
5    121    1