tailieunhanh - Beginning Visual Basic .NET Database Programming phần 10

Hãy tưởng tượng chúng ta phải cập nhật bảng Sản phẩm. (Các thuật toán thực tế chúng ta sẽ đặt lại với nhau sẽ làm việc trên DataSet bất kỳ, không chỉ là một rút ra từ bảng sản phẩm.) Đây là những gì chúng ta sẽ làm:ProviderConnection. Phương pháp này sẽ chấp nhận một DataSet hàng rút ra từ bảng Products. | Disconnected Data Imagine we have to update the Products table. The actual algorithm we re going to put together will work on any DataSet not just one drawn from the Products table. Here s what we ll do Create a new method called SetProductDetails on Providerconnection. This method will accept a DataSet of rows drawn from the Products table. This will be known as the Changed DataSet . We ll examine each row in the Changed DataSet in turn looking for ones that have their RowState property set to Modified. When we find one we ll get the same product back from the database. This time however we ll keep the SqlDataAdapter around and keep it bound to the DataSet. This new DataSet will be called the Master DataSet . All of the columns in the applicable row in the Changed DataSet will be copied to the matching column in the Master DataSet. We ll use the SqlDataAdapter object s Update method to make the changes to the database itself. This technique will work whether the Changed DataSet is passed directly to DirectConnection or through RemoteConnection and the Web Service. The only drawback is that we have to create two SqlDataAdapter objects whereas if we only had to deal with a direct connection we d need just one. Building SetProductDetails The first thing we need to do is add SetProductDetails to the abstract ProviderConnection object. Try It Out - Building SetProductDetails 1. Op en the code editor for ProviderConnection. Add this method GetSuppliers - get the entire supplier list. Public MustOverride Function GetSuppliers As DataSet SetProductDetails - set the details for products. Public MustOverride Sub SetProductDetails ByVal products As DataSet End Class 2. Open RemoteConnection and add stub method. As before we ll come back and fill this in later. Public Overrides Sub SetProductDetails ByVal products As End Sub 3. Open DirectConnection and add this method 55 Chapter 14 SetProductDetails - save changes to changed products. Public Overrides Sub