Home All Groups Group Topic Archive Search About

VB6 - Saving query results as XML

Author
19 Feb 2007 2:33 PM
Bod
Hi,

How can I issue a SQL query from my VB program and get the results back as
XML?

Normally I do:
strSQL = "SELECT * FROM MyTable"
RS.Open strSQL, conn, adOpenKeyset, adLockOptimistic
to return an ADODB recordset (RS).

However if I want the results as XML I could use
"SELECT * FROM MyTable FOR XML AUTO"
but then in what structure do the results get returned - a string?  What if
the results are too big for a string variable?
I've tried setting up an ADODB.Command (Cmd) and issuing Cmd.Execute but how
do I assign the results to a variable in the program?

Has anyone got any ideas?
Thanks
Bod

Author
19 Feb 2007 4:18 PM
Jan Hyde
Bod <B**@discussions.microsoft.com>'s wild thoughts were
released on Mon, 19 Feb 2007 06:33:13 -0800 bearing the
following fruit:

Show quoteHide quote
>Hi,
>
>How can I issue a SQL query from my VB program and get the results back as
>XML?
>
>Normally I do:
>strSQL = "SELECT * FROM MyTable"
>RS.Open strSQL, conn, adOpenKeyset, adLockOptimistic
>to return an ADODB recordset (RS).
>
>However if I want the results as XML I could use
>"SELECT * FROM MyTable FOR XML AUTO"
>but then in what structure do the results get returned - a string?  What if
>the results are too big for a string variable?
>I've tried setting up an ADODB.Command (Cmd) and issuing Cmd.Execute but how
>do I assign the results to a variable in the program?
>

I have no idea about returning XML, but I do know an ADO
recordset allows you to save the results as an XML file.




Jan Hyde (VB MVP)

--
Meditation is not what you think.
Author
19 Feb 2007 5:34 PM
Bod
Show quote Hide quote
"Jan Hyde" wrote:

> Bod <B**@discussions.microsoft.com>'s wild thoughts were
> released on Mon, 19 Feb 2007 06:33:13 -0800 bearing the
> following fruit:
>
> >Hi,
> >
> >How can I issue a SQL query from my VB program and get the results back as
> >XML?
> >
> >Normally I do:
> >strSQL = "SELECT * FROM MyTable"
> >RS.Open strSQL, conn, adOpenKeyset, adLockOptimistic
> >to return an ADODB recordset (RS).
> >
> >However if I want the results as XML I could use
> >"SELECT * FROM MyTable FOR XML AUTO"
> >but then in what structure do the results get returned - a string?  What if
> >the results are too big for a string variable?
> >I've tried setting up an ADODB.Command (Cmd) and issuing Cmd.Execute but how
> >do I assign the results to a variable in the program?
> >
>
> I have no idea about returning XML, but I do know an ADO
> recordset allows you to save the results as an XML file.
>
>
>
>
> Jan Hyde (VB MVP)
>
> --
> Meditation is not what you think.
>
> Really?  So if I have a variable RS returned as an ADO recordset I can save that as XML?  What method performs that trick?

Bod
Author
20 Feb 2007 9:02 AM
Jan Hyde
Bod <B**@discussions.microsoft.com>'s wild thoughts were
released on Mon, 19 Feb 2007 09:34:05 -0800 bearing the
following fruit:

Show quoteHide quote
>
>
>"Jan Hyde" wrote:
>
>> Bod <B**@discussions.microsoft.com>'s wild thoughts were
>> released on Mon, 19 Feb 2007 06:33:13 -0800 bearing the
>> following fruit:
>>
>> >Hi,
>> >
>> >How can I issue a SQL query from my VB program and get the results back as
>> >XML?
>> >
>> >Normally I do:
>> >strSQL = "SELECT * FROM MyTable"
>> >RS.Open strSQL, conn, adOpenKeyset, adLockOptimistic
>> >to return an ADODB recordset (RS).
>> >
>> >However if I want the results as XML I could use
>> >"SELECT * FROM MyTable FOR XML AUTO"
>> >but then in what structure do the results get returned - a string?  What if
>> >the results are too big for a string variable?
>> >I've tried setting up an ADODB.Command (Cmd) and issuing Cmd.Execute but how
>> >do I assign the results to a variable in the program?
>> >
>>
>> I have no idea about returning XML, but I do know an ADO
>> recordset allows you to save the results as an XML file.
>>
>>
>>
>>
>> Jan Hyde (VB MVP)
>>
>> --
>> Meditation is not what you think.
>>
>> Really?  So if I have a variable RS returned as an ADO recordset I can save that as XML?  What method performs that trick?
>
>Bod

Sure, look at the save method. Also you can load the XML
back into a ADO recordset.



Jan Hyde (VB MVP)

--
Unaccustomed as I am to puppies squeaking, I would like to display a few birds.

(Keith Jackson)
Author
23 Feb 2007 3:44 PM
Bod
Thanks very much to you both.  I hadn't realised there was an XML option on
Save.
It seems to automatically dump out the schema as well as the data, but that
isn't a problem.
Bod


Show quoteHide quote
"Jan Hyde" wrote:

> Bod <B**@discussions.microsoft.com>'s wild thoughts were
> released on Mon, 19 Feb 2007 09:34:05 -0800 bearing the
> following fruit:
>
> >
> >
> >"Jan Hyde" wrote:
> >
> >> Bod <B**@discussions.microsoft.com>'s wild thoughts were
> >> released on Mon, 19 Feb 2007 06:33:13 -0800 bearing the
> >> following fruit:
> >>
> >> >Hi,
> >> >
> >> >How can I issue a SQL query from my VB program and get the results back as
> >> >XML?
> >> >
> >> >Normally I do:
> >> >strSQL = "SELECT * FROM MyTable"
> >> >RS.Open strSQL, conn, adOpenKeyset, adLockOptimistic
> >> >to return an ADODB recordset (RS).
> >> >
> >> >However if I want the results as XML I could use
> >> >"SELECT * FROM MyTable FOR XML AUTO"
> >> >but then in what structure do the results get returned - a string?  What if
> >> >the results are too big for a string variable?
> >> >I've tried setting up an ADODB.Command (Cmd) and issuing Cmd.Execute but how
> >> >do I assign the results to a variable in the program?
> >> >
> >>
> >> I have no idea about returning XML, but I do know an ADO
> >> recordset allows you to save the results as an XML file.
> >>
> >>
> >>
> >>
> >> Jan Hyde (VB MVP)
> >>
> >> --
> >> Meditation is not what you think.
> >>
> >> Really?  So if I have a variable RS returned as an ADO recordset I can save that as XML?  What method performs that trick?
> >
> >Bod
>
> Sure, look at the save method. Also you can load the XML
> back into a ADO recordset.
>
>
>
> Jan Hyde (VB MVP)
>
> --
> Unaccustomed as I am to puppies squeaking, I would like to display a few birds.
>
> (Keith Jackson) 
>
>