Microsoft Knowledge Base Email Alertz

KBAlertz.com: (263247) - If you have an XML string or document you may use it to open an ActiveX Data Objects (ADO) recordset. You can do this by using the Microsoft ADO 2.5 Stream object and the new XML integration features in ADO. This article describes the mechanism...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 263247 - Last Review: July 1, 2004 - Revision: 5.4

How To Obtain an ADO Recordset from XML

This article was previously published under Q263247

SUMMARY

If you have an XML string or document you may use it to open an ActiveX Data Objects (ADO) recordset. You can do this by using the Microsoft ADO 2.5 Stream object and the new XML integration features in ADO.

This article describes the mechanism required to load the following into an ADO 2.5 recordset:
  • A string containing XML.

    -and-

  • An XML DOM Document instance.
Provided the XML data is in the format where ADO recordset can accept.

MORE INFORMATION

To open an XML string as a recordset, use the code that follows. Make sure that your Visual Basic project has the appropriate references to the Microsoft ActiveX Data Access Components 2.5 Library so that ADO can be used as shown.

Sample Code
Public Function RecordsetFromXMLString(sXML As String) As Recordset

    Dim oStream As ADODB.Stream
    Set oStream = New ADODB.Stream
    
    oStream.Open
    oStream.WriteText sXML   'Give the XML string to the ADO Stream

    oStream.Position = 0    'Set the stream position to the start

    Dim oRecordset As ADODB.Recordset
    Set oRecordset = New ADODB.Recordset
       
    oRecordset.Open oStream    'Open a recordset from the stream

    oStream.Close
    Set oStream = Nothing

    Set RecordsetFromXMLString = oRecordset  'Return the recordset

    Set oRecordset = Nothing

End Function
Please note that the preceding code accepts a String.


The following code accepts a DOM object as the source for the recordset. Note that the Stream object is not needed:

Public Function RecordsetFromXMLDocument(XMLDOMDocument As DOMDocument) As Recordset
    Dim oRecordset As ADODB.Recordset
    
    Set oRecordset = New ADODB.Recordset
       
    oRecordset.Open XMLDOMDocument 'pass the DOM Document instance as the Source argument

    Set RecordsetFromXMLDocument = oRecordset  'return the recordset

    Set oRecordset = Nothing

End Function
After you open the recordset in any of these ways, you can use the recordset as any other disconnected recordset.

Note that the current position, AbsolutePage and other navigation properties are not stored in the XML document; therefore, the newly opened recordset is always positioned at the first row.

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
309702  (http://kbalertz.com/Feedback.aspx?kbNumber=309702/EN-US/ ) How To Read XML Data into a DataSet by Using Visual Basic .NET
For more information about ADO, see to the following Web site:
http://msdn.microsoft.com/en-us/data/aa937729.aspx (http://msdn.microsoft.com/en-us/data/aa937729.aspx)
(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by Edward A. Jezierski, Microsoft Corporation.


APPLIES TO
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
  • Microsoft XML Core Services 4.0
  • Microsoft XML Parser 2.5
  • Microsoft XML Parser 2.6
  • Microsoft XML Parser 3.0
Keywords: 
kbcodesnippet kbhowto KB263247
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please