[Previous] [Contents] [Next]

Inputting Data as XML Using ADO 2.5

Reading the XML data generated by ADO 2.5 is just as easy as outputting the data. To examine how to input data as XML using ADO 2.5 in the example application, add another command button to the frmADOXML form and call it cmdRetrieve with a caption Retrieve&Add. Add the following code to the click event handler of the command button cmdRetrieve:


  Private Sub cmdRetrieve_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
      'Add a new record.
      objNWRecordset.AddNew
      objNWRecordset.Fields("ProductName") = "Test"

  End Sub

NOTE
An error will be raised if you run this code without adding the rs:updatable='true' attribute to the schema section of the generated XML file.

Setting Options to adCmdFile tells ADO that this data will be coming from a regular file and not from a database.

Once you add a new record, edit a record, or delete a record, you must call the Update method of the ADO recordset. Each time you call the Update method, the updated record is marked within the recordset. If you make changes to the recordset and save the changes to a file, you can see the actual changes. These changes are being made only to the recordset, not to the actual data in the database, as there is no connection to the database.

[Previous] [Contents] [Next]