Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass XML from C# to a stored procedure in SQL Server 2008?
    primarykey
    data
    text
    <p>I want to pass xml document to sql server stored procedure such as this:</p> <pre><code>CREATE PROCEDURE BookDetails_Insert (@xml xml) </code></pre> <p>I want compare some field data with other table data and if it is matching that records has to inserted in to the table.</p> <p>Requirements:</p> <ol> <li><p>How do I pass XML to the stored procedure? I tried this, but it doesn’t work:<strong>[Working]</strong></p> <pre><code>command.Parameters.Add( new SqlParameter("@xml", SqlDbType.Xml) { Value = new SqlXml(new XmlTextReader(xmlToSave.InnerXml, XmlNodeType.Document, null)) }); </code></pre></li> <li><p>How do I access the XML data within the stored procedure? </p></li> </ol> <p>Edit: <strong>[Working]</strong></p> <pre><code> String sql = "BookDetails_Insert"; XmlDocument xmlToSave = new XmlDocument(); xmlToSave.Load("C:\\Documents and Settings\\Desktop\\XML_Report\\Books_1.xml"); SqlConnection sqlCon = new SqlConnection("..."); using (DbCommand command = sqlCon.CreateCommand()) { **command.CommandType = CommandType.StoredProcedure;** command.CommandText = sql; command.Parameters.Add( new SqlParameter("@xml", SqlDbType.Xml) { Value = new SqlXml(new XmlTextReader(xmlToSave.InnerXml , XmlNodeType.Document, null)) }); sqlCon.Open(); DbTransaction trans = sqlCon.BeginTransaction(); command.Transaction = trans; try { command.ExecuteNonQuery(); trans.Commit(); sqlCon.Close(); } catch (Exception) { trans.Rollback(); sqlCon.Close(); throw; } </code></pre> <p><strong>Edit 2</strong>: How to create a select query to select pages, description based on some conditions.</p> <pre><code> &lt;booksdetail&gt; &lt;isn_13&gt;700001048&lt;/isbn_13&gt; &lt;isn_10&gt;01048B&lt;/isbn_10&gt; &lt;Image_URL&gt;http://www.landt.com/Books/large/00/7010000048.jpg&lt;/Image_URL&gt; &lt;title&gt;QUICK AND FLUPKE&lt;/title&gt; &lt;Description&gt; PRANKS AND JOKES QUICK AND FLUPKE &lt;/Description&gt; &lt;/booksdetail&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload