tags:

views:

60

answers:

1

Hi. 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? Thanks.

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

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

        return result;
+1  A: 

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();
tmp.Read();
while (!tmp.EOF) {
    string name = tmp["AttributeName"];
    string s = tmp.ReadOuterXml();
}
Phaedrus
It turns out both method works. What's going wrong is in my SP.But anyway, thanks Phaedrus
Wenyang