devxlogo

Quickly Convert Recordset into an XML File

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:MyFolderMyTable.xml", adPersistXML   ' Close Recordset   oRecordset.CloseEnd Sub
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist