SqlCommand cmd = new SqlCommand(); | |
cmd.CommandText = sQuery; | |
cmd.Connection = oConn; | |
cmd.CommandType = CommandType.Text; | |
XmlReader xmlRead = cmd.ExecuteXmlReader(); | |
| |
XPathDocument xp = new XPathDocument(xmlRead); | |
XPathNavigator xn = xp.CreateNavigator(); | |
XmlDocument xd = new XmlDocument(); | |
XmlNode root = xd.CreateElement(sRootName); | |
root.InnerXml = xn.OuterXml; | |
xd.AppendChild(root); | |
oConn.Close(); | |
return xd; |
Or you could just use, as I found out later, FOR XML AUTO, ELEMENTS, ROOT('ElementName') which works even better and then no messing around with C#.
No comments:
Post a Comment