C# – how to fetch result from “for xml path”


Now I have a stored procedure (SQL server) which will return a XML from "for xml path" statement. I've try to read the response with ExecuteXmlReader and ExecuteReader, but I got nothing.
I've google a while but still can't find how to extract the return value, or, how to retrive the return value. Should I use ExecuteXmlReader? or something else?

        string result = "";
        XmlReader tmp = cmd.ExecuteXmlReader();

        while (tmp.Read())
            string s = tmp.Value;

        return result;

Best Solution

The ReadOuterXml method returns the current node and all of it's children if positioned on an element or attribute node, otherwise it returns an empty string. You can read the nodes attributes by index or name.

XmlReader tmp = cmd.ExecuteXmlReader();
while (!tmp.EOF) {
    string name = tmp["AttributeName"];
    string s = tmp.ReadOuterXml();