views:

83

answers:

2

Hello,

I'm trying to write the result of a FOR XML PATH query to a file. I can generate the file, but it doesn't contain the results of the query. Any one know where i'm going wrong?

private static void GetChartData(string OC_Ttl1, string OC_Ttl2, string OC_OL31)
    {

        //Prepare Connection Variables
        SqlConnection conn_Org = new SqlConnection();
        SqlCommand cmd_Org = new SqlCommand();



        //Open Connection
        conn_Org.ConnectionString = Set_OrgChartConn();
        conn_Org.Open();

        //Execute Procedure
        cmd_Org.Connection = conn_Org;
        cmd_Org.CommandText = "dbo.usp_CreateOrgDataSet";
        cmd_Org.CommandType = CommandType.StoredProcedure;
        cmd_Org.Parameters.AddWithValue("@OC_Ttl_1", OC_Ttl1);
        cmd_Org.Parameters.AddWithValue("@OC_Ttl_2", OC_Ttl2);
        cmd_Org.Parameters.AddWithValue("@OC_OL3_1", OC_OL31);




        DataSet myDataSet = new DataSet();
        myDataSet.ReadXml(cmd_Org.ExecuteXmlReader(), XmlReadMode.Fragment);
        myDataSet.WriteXml("myData.xml");

        conn_Org.Close();






    }

THis is the contents of the xml file that is generated with the above code.

<?xml version="1.0" standalone="yes"?>

A: 

Try this:

myDataSet.ReadXml(cmd_Org.ExecuteXmlReader(), XmlReadMode.Auto);
Andrew Hare
Magic. Thank you. Apologies for the late response - i've been on Holiday
Doozer1979
A: 

What happens if you call the stored procedure from sql management studio? Are you definitely getting the xml back?

ilivewithian
Thank you for the response. Andrew Hare fixed my problem. Apologies for the late response - i've been on Holiday
Doozer1979