Fog Creek Software
Discussion Board

XML to ADO Conversion


I'm not an ADO expert and I need some advice rather urgently concerning the transformation of an XML document into ADO.

Do I have to specify the datatype and length of every field when converting the XML or can ADO handle this dynamically? Currently we are using XML templates with datatype and length defined to accomplish this but it is proving to laborious given the number of templates required.

Note: The datatype and length is NOT being sent with the XML.

Thanks in advance,


Damian Harvey
Monday, August 26, 2002

C# code

DataSet ds = new DataSet();


Once you read the XML into the dataset, the sky in the limit. Everything is taken care of.

Monday, August 26, 2002

He said ADO not ADO.NET

Luke Duff
Monday, August 26, 2002

To put XML (in a string strXML) back into a recordset (in VB6 and ADO), use code similar to:
    Dim oRS As ADODB.Recordset
    Dim oStream As ADODB.Stream
    Set oStream = New ADODB.Stream
    Set oRS = New ADODB.Recordset
    oStream.WriteText strXML
    oStream.Position = 0
    oRS.Open oStream
    'oRS is now a valid, disconnected recordset
This requires that strXML contains a structure that is understood by ADO as a recordset.

One way to get this structure is to save a recordset in XML format, as follows:
    rsData.Save oStream, adPersistXML
    strOriginalXML = oStream.ReadText(adReadAll)

If your XML document does not have datatype/schema information, you could create the complete XML recordset structure by converting a 1-row recordset to XML as above, and then replace the
"<rs:data><z:row ..... /></rs:data>"
portion of the XML file with the data from your XML document, before converting it back to ADO.

Philip Dickerson
Monday, August 26, 2002

*  Recent Topics

*  Fog Creek Home