tailieunhanh - Using Stored Procedures to Add, Modify, and Remove Rows from the Database phần 2
Setting the InsertCommand Property of a DataAdapter The following example creates a SqlCommand object named myInsertCommand that contains a call to the AddProduct4() stored procedure | Setting the InsertCommand Property of a DataAdapter The following example creates a SqlCommand object named mylnsertCommand that contains a call to the AddProduct4 stored procedure SqlCommand mylnsertCommand EXECUTE @MyProductID AddProduct4 @MyProductName @MyUnitPrice @MyProductID 0 ProductID @MyProductID .Direction @MyProductName 40 ProductName @MyUnitPrice 0 UnitPrice As you can see from the previous code the direction of the @MyProductID parameter is set to which indicates that this parameter is an output parameter. Also the maximum length of the @MyProductID and @MyUnitPrice parameters is set to 0 in the third parameter to the Add method. Setting them to 0 is fine because the maximum length doesn t apply to fixed length types such as numbers only to types such as strings. Next the following example sets the InsertCommand property of mySqlDataAdapter to myInsertCommand myInsertCommand Setting the UpdateCommand Property of a DataAdapter The following example creates a SqlCommand object named myUpdateCommand that contains a call to the UpdateProduct stored procedure and sets the UpdateCommand property of mySqlDataAdapter to myUpdateCommand SqlCommand myUpdateCommand EXECUTE UpdateProduct @OldProductID @NewProductName @NewUnitPrice @OldProductName @OldUnitPrice @OldProductID 0 ProductID @NewProductName 40 ProductName @NewUnitPrice 0 UnitPrice @OldProductName 40 ProductName .
đang nạp các trang xem trước