Posted on 2009-12-18
Last Modified: 2012-05-08
I have a query in a classic web application, using an ODBC connection to sql server.  The query contains FOR XML PATH.  The query runs fine, but that data returned is blank.  If I run the query in the management studio, it works fine.  Any ideas?
Question by:cartch2008
    LVL 15

    Expert Comment

    I think this could help you
    OdbcConnection conn = new OdbcConnection("DSN=AdventureWorks");
    OdbcDataAdapter daProducts = new OdbcDataAdapter("SELECT ProductID, Name FROM Production.Product FOR XML PATH('Product'), ROOT('Products')", conn);
    DataSet dsResult = new DataSet();
    string yourXML = dsResult.GetXml();

    Open in new window


    Author Comment

    classic asp, not .net
    LVL 28

    Accepted Solution


    or see attached code
    Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0")
    Set oCmd = Server.CreateObject("ADODB.Command")
    oCmd.ActiveConnection = yourconnectionobject
    oCmd.Properties("xml root") = "root"
    oCmd.Properties("Output Stream") = oXML
    oCmd.CommandText = sSQL    'your FOR XML statement here
    oCmd.Execute , , 1025      ' =  adExecuteStream + adCmdText

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now