How to convert XmlDocument to XmlReader for SqlXml data type.
1 min read
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); }
Share:
Share on LinkedIn
Quick Share: Your custom post text has been copied to your clipboard! Click the button below to open LinkedIn's share dialog, then paste it.
💡 Tip: LinkedIn will open in a new tab. Use Ctrl+V (or Cmd+V on Mac) to paste your text.
Note: LinkedIn will show the article preview. You can add your custom text above it.