Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VB6-WebClass: Sending XML from Ado-RecordSet

2 views
Skip to first unread message

franc

unread,
Jun 6, 2006, 3:42:56 PM6/6/06
to
Hello,
i spent half a night to find out how it is possible to send the content
of a (ADO-)Recordset (classic, not ADO.NET) as XML (without creating it
by myself) with the Response.Write Method.
I have an old VB6 Web-Application and want to use it for an auto
fill-in with AJAX (clientside).
Here i need some XML for the XMLHttpRequest-answer.
When i return the result of a query in VB by the WriteTemplate Method
it is normal text.
But if i want to have the XMLHttpRequest.responseXML which is empty,
when i return only text.
Its very easy, if you know it (at least i found it on the msdn):

' ...my recordset rs ist already filled with the sql-result

' first initialising the Response-object
Response.ContentType = "text/xml"
Response.Expires = 0
Response.Buffer = False

' the xml-header
Response.Write "<?xml version='1.0'?>" & vbNewLine

' and thats the trick: the save method of the recordset
' with Response as Destination
' and adPersistXML as type
rs.Save Response, adPersistXML

' this is wellknown and saves the recordset to a file (as xml)
rs.Save App.Path & "\" & "RS " & Replace(Now, ":", "-") & _
".xml", adPersistXML

greetings,
franc walter

franc

unread,
Jun 7, 2006, 4:43:26 PM6/7/06
to
look at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdhowstep3senddata.asp

but don't use this ms-xml style for serious purposes in a
XmlHttpRequest(e.g. firefox...) -
DOM may not work.
make it yourself, for example:

Function AdoToXML(ByRef rs As ADODB.Recordset) As String
'rs is the recordset filled with data
Dim l As Long, k As Long
AdoToXML = "<?xml version=""1.0"" encoding=""iso-8859-1""?>" &
vbNewLine
AdoToXML = AdoToXML & "<rs>" & vbNewLine
For l = 0 To rs.RecordCount - 1
AdoToXML = AdoToXML & "<rs" & CStr(l) & ">" & vbNewLine
For k = 0 To rs.Fields.Count - 1
AdoToXML = AdoToXML & "<" & rs.Fields(k).Name & ">" & vbNewLine
AdoToXML = AdoToXML & rs.Fields(k).Value & vbNewLine
AdoToXML = AdoToXML & "</" & rs.Fields(k).Name & ">" & vbNewLine
Next k
AdoToXML = AdoToXML & "</rs" & CStr(l) & ">" & vbNewLine
rs.MoveNext
Next l
AdoToXML = AdoToXML & "</rs>" & vbNewLine
End Function

(no garantee)
franc

0 new messages