30 January 2007
How to convert XmlDocument to XmlReader for SqlXml data type.
The SqlXml datatype constructor only accepts a Stream or XmlReader, if you have an XmlDocument in memory (go with stream if you have it) then you can easily convert to a SqlXml compatible stream with the XmlNodeReader class.
XmlNodeReader implements IDisposable, so wrap it in a using or try/catch.
For example:
XmlDocument xml = new XmlDocument();
using (XmlNodeReader xnr = new XmlNodeReader(xml))
{
SqlXml sx = new SqlXml(xnr);
}
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using
Comments
Leave a Comment
Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.