Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSave an ADO Recordset's data into an XML file
DescriptionThis example shows how to save an ADO Recordset's data into an XML file in Visual Basic 6.
KeywordsADO, Recordset, XML, URL, Web, data, Access
CategoriesDatabase, Internet
 
Thanks to James Hansen.

When you click the "Make XML File" button, the program uses the following code to make such an XML file. It opens an ADO Recordset connected to a normal Access database file. It then creates an XML DOMDocument object and calls the Recordset's Save method, passing it the DOMDocument to save the Recordset's data into the document. It then calls the DOMDocument object's Save method to write the document's XML data into a file.

 
Private Sub cmdMakeXmlFile_Click()
Dim db_name As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim dom_document As DOMDocument

    ' Get the database's name.
    db_name = txtDatabase.Text

    ' Open the connection.
    Set conn = New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Persist Security Info=False;" & _
        "Data Source=" & db_name
    conn.Open

    ' Open the Recordset.
    Set rs = conn.Execute("SELECT * FROM Books ORDER BY " & _
        "Title")

    ' Save the data into a DOMDocument.
    Set dom_document = New DOMDocument
    rs.Save dom_document, adPersistXML

    rs.Close
    conn.Close

    ' Save the XML data into an XML file.
    db_name = Replace$(db_name, ".mdb", ".xml")
    dom_document.Save db_name
    MsgBox "Now move the XML file to a HTTP site."
End Sub
 
See also Connect an ADO Recordset to an XML file located at a URL.

For information on using XML in Visual Basic .NET, see my book Visual Basic .NET and XML.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated