Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1030505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:42:38+00:00 2026-05-16T12:42:38+00:00

I want to pass xml document to sql server stored procedure such as this:

  • 0

I want to pass xml document to sql server stored procedure such as this:

CREATE PROCEDURE BookDetails_Insert (@xml xml)

I want compare some field data with other table data and if it is matching that records has to inserted in to the table.

Requirements:

  1. How do I pass XML to the stored procedure? I tried this, but it doesn’t work:[Working]

    command.Parameters.Add(
        new SqlParameter("@xml", SqlDbType.Xml)
        {
            Value = new SqlXml(new XmlTextReader(xmlToSave.InnerXml,
                               XmlNodeType.Document, null))
        });
    
  2. How do I access the XML data within the stored procedure?

Edit: [Working]

 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;
            }

Edit 2: How to create a select query to select pages, description based on some conditions.

  <booksdetail> <isn_13>700001048</isbn_13> <isn_10>01048B</isbn_10>       
    <Image_URL>http://www.landt.com/Books/large/00/7010000048.jpg</Image_URL>   
    <title>QUICK AND FLUPKE</title> <Description> PRANKS AND JOKES QUICK AND FLUPKE </Description> </booksdetail> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:42:39+00:00Added an answer on May 16, 2026 at 12:42 pm

    For part 2 of your question, see my answer to Stored procedure: pass XML as an argument and INSERT (key/value pairs) for an example of how to use XML within a stored procedure.

    EDIT: Sample code below is based on the specific example given in the comments.

    declare @MyXML xml
    
    set @MyXML = '<booksdetail> 
                      <isbn_13>700001048</isbn_13> 
                      <isbn_10>01048B</isbn_10> 
                      <Image_URL>http://www.landt.com/Books/large/00/70100048.jpg</Image_URL> 
                      <title>QUICK AND FLUPKE</title> 
                      <Description> PRANKS AND JOKES QUICK AND FLUPKE - CATASTROPHE QUICK AND FLUPKE </Description> 
                  </booksdetail>'
    
    select Book.detail.value('(isbn_13/text())[1]','varchar(100)') as isbn_13, 
           Book.detail.value('(isbn_10/text())[1]','varchar(100)') as isbn_10, 
           Book.detail.value('(Image_URL/text())[1]','varchar(100)') as Image_URL, 
           Book.detail.value('(title/text())[1]','varchar(100)') as title, 
           Book.detail.value('(Description/text())[1]','varchar(100)') as Description
        from @MyXML.nodes('/booksdetail') as Book(detail)     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass external XML a variable. How do I do this? WHAT
I am returning XML from a stored procedure, that I want to capture in
I have an xml document which i want to pass as a parameter to
I want to pass XML as a string in an XML attribute. <activity evt=&lt;FHS&gt;
I want to pass an uninitialized object pointer to some method. Within that method
I am using ms sql server 2005 and I want to do a mass
I need to pass an XML document to the web service. Is it possible
I have the following XML document: <x> <a>Some text</c> <b>Some text 2</b> <c>Some text
I want to do following: Make Oracle stored procedure for read all data from
I want to ship some default data with my app. This data can be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.