Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Enterprise
Expertise: Beginner
Feb 1, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Quickly Convert Recordset into an XML File

With MDAC 2.1 (Microsoft Data Access Components), you can generate a XML file quickly from a Recordset object.

The Save() method of Recordset object takes in an optional parameter, adPersistXML, of type "PersistFormatEnum." By specifying adPersistXML in the Save() method, you can save the Recordset object into a file in XML format. Similarly, you can reopen a Recordset by providing a previously saved XML file.

Here is an example that saves a Recordset as an XML file:

 Public Sub GenerateXML()
   Dim oRecordset As ADODB.Recordset
   ' Create Recordset object
   Set oRecordset = CreateObject("ADODB.Recordset")
   ' Open Recordset
   oRecordset.Open "SELECT * FROM MyTable", _
      "DSN=Sample;Provider=MSDASQL; uid=sa;pwd=;", _
      adOpenDynamic, adLockOptimistic, adCmdText
   ' Save Recordset as an XML file
   oRecordset.Save "C:\MyFolder\MyTable.xml", adPersistXML
   ' Close Recordset
End Sub
Deepak Pant
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date