Private Sub cmdMakeChanges_Click() Dim objNWRecordset As ADODB.Recordset Set objNWRecordset = New ADODB.Recordset 'Open the recordset to a file as XML objNWRecordset.Open "C:\Products.XML", Options:=adCmdFile objNWRecordset.Fields("ProductName") = "Test" objNWRecordset.Update objNWRecordset.MoveLast objNWRecordset.Delete objNWRecordset.Update objNWRecordset.Filter = adFilterPendingRecords objNWRecordset.Save "c:\ProductsUpdate.xml", adPersistXML End Sub
In this case, we have changed the product name of the first record to Test and deleted the last record. The changed recordset is then saved to the ProductUpdate.xml file. You can see the following new additions in the ProductUpdate.xml file after clicking the Make Changes command button:
<rs:update> <rs:original> <z:row ProductID='1' ProductName='Chai' SupplierID='1' CategoryID='1' QuantityPerUnit='10 boxes x 20 bags' UnitPrice='18' UnitsInStock='39' UnitsOnOrder='0' ReorderLevel='10' Discontinued='False'/> </rs:original> <z:row ProductName='Test'/> </rs:update> <rs:delete> <z:row ProductID='77' ProductName='Original Frankfurter grne Soe' SupplierID='12' CategoryID='2' QuantityPerUnit='12 boxes' UnitPrice='13' UnitsInStock='32' UnitsOnOrder='0' ReorderLevel='15' Discontinued='False'/> </rs:delete>
With the updated XML file, ADO can reconstruct a recordset that has the original and new values for fields that are edited and can determine which rows have been deleted. Now let's look at how we would actually update the data source.