tailieunhanh - Adding, Updating, and Deleting Related Rows In this section, you'll learn how to make changes in

Adding, Updating, and Deleting Related Rows In this section, you'll learn how to make changes in DataTable objects that store rows from the Customers and Orders tables | Adding Updating and Deleting Related Rows In this section you ll learn how to make changes in DataTable objects that store rows from the Customers and Orders tables. These tables are related through the CustomerlD foreign key. As you ll see you must push changes to the underlying database tables in a specific order. If you don t your program will throw an exception. Note You ll find all the code examples shown in this section in the program. Setting Up the DataAdapter Objects You ll need two DataAdapter objects One to work with the Customers table which will be named customersDA. One to work with the Orders table which will be named ordersDA. Let s take a look at setting up these two DataAdapter objects. Setting Up the customersDA DataAdapter The following code creates and sets up a DataAdapter named customersDA that contains the necessary SELECT INSERT UPDATE and DELETE statements to access the Customers table SqlDataAdapter customersDA new SqlDataAdapter create a SqlCommand object to hold the SELECT SqlCommand customersSelectCommand SELECT CustomerlD CompanyName FROM Customers create a SqlCommand object to hold the INSERT SqlCommand customersInsertCommand customersInsertCommand. CommandText INSERT INTO Customers CustomerID CompanyName VALUES @CustomerID @CompanyName @CustomerID S 5 CustomerlD @CompanyName 40 CompanyName create a SqlCommand object to hold the UPDATE SqlCommand customersUpdateCommand UPDATE Customers SET CompanyName @NewCompanyName WHERE CustomerlD @OldCustomerID AND CompanyName @OldCompanyName @NewCompanyName 40 CompanyName @OldCustomerID 5 .

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