tailieunhanh - Using Stored Procedures to Add, Modify, and Remove Rows from the Database phần 1
Using Stored Procedures to Add, Modify, and Remove Rows from the Database You can get a DataAdapter object to call stored procedures to add, modify, and remove rows from the database. | Using Stored Procedures to Add Modify and Remove Rows from the Database You can get a DataAdapter object to call stored procedures to add modify and remove rows from the database. These procedures are called instead of the INSERT UPDATE and DELETE statements you ve seen how to set in a DataAdapter object s InsertCommand UpdateCommand and DeleteCommand properties. The ability to call stored procedures using a DataAdapter is a very powerful addition to . For example you can use a stored procedure to add a row to a table containing an identity column and then retrieve the new value for that column generated by the database. You can also do additional work in a stored procedure such as inserting a row into an audit table when a row is modified. You ll see examples of both these scenarios in this section. Tip Using stored procedures instead of INSERT UPDATE and DELETE statements can also improve performance. You should use stored procedures if your database supports them. SQL Server and Oracle support stored procedures. Oracle stored-procedures are written in PL SQL. The ProductID column of the Products table is an identity column and you saw a number of stored procedures in Chapter 4 Introduction to Transact-SQL Programming that added a row to the Products table and returned the ProductID. In this section you ll see how to Create the required stored procedures in the Northwind database. Set up a DataAdapter to call the stored procedures. Add modify and remove a DataRow to from a DataTable. The C methods shown in this section follow the same steps as shown in the earlier section Modifying Rows in a DataTable. Note You ll find a complete program named in the ch11 directory that illustrates the use of the methods shown in this section. The listing for this program is omitted from this book for brevity. Creating the Stored Procedures in the Database You ll create the following three stored procedures in the Northwind database .
đang nạp các trang xem trước