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 279057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:00:01+00:00 2026-05-12T05:00:01+00:00

I am new to C# so I apologize if this is a simple task.

  • 0

I am new to C# so I apologize if this is a simple task. What I would like to do open an XML file whose root node is a table name and the children of the root node are field names and values. I would then like to map the fields to the root node’s table in a SQL Server database and update or insert as needed. Does anyone know if there is a more elegant way to do this than looping through the node tree and building out the SQL string? It seems like there should be a way to bind the fields as if the XML document were a form, only it would only exist in memory. Again, sorry if this question has an obvious answer. Thanks in advance for any help.

  • 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-12T05:00:01+00:00Added an answer on May 12, 2026 at 5:00 am

    I use OPENXML method to solve such tasks. There is example from BOL how to select the data from XML:

    DECLARE @idoc int
    DECLARE @doc varchar(1000)
    SET @doc ='
    <ROOT>
    <Customer CustomerID="VINET" ContactName="Paul Henriot">
       <Order OrderID="10248" CustomerID="VINET" EmployeeID="5" 
               OrderDate="1996-07-04T00:00:00">
          <OrderDetail ProductID="11" Quantity="12"/>
          <OrderDetail ProductID="42" Quantity="10"/>
       </Order>
    </Customer>
    <Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
       <Order OrderID="10283" CustomerID="LILAS" EmployeeID="3" 
               OrderDate="1996-08-16T00:00:00">
          <OrderDetail ProductID="72" Quantity="3"/>
       </Order>
    </Customer>
    </ROOT>'
    --Create an internal representation of the XML document.
    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
    -- SELECT stmt using OPENXML rowset provider
    SELECT *
    FROM   OPENXML (@idoc, '/ROOT/Customer/Order/OrderDetail',2)
             WITH (OrderID       int         '../@OrderID',
                   CustomerID  varchar(10) '../@CustomerID',
                   OrderDate   datetime    '../@OrderDate',
                   ProdID      int         '@ProductID',
                   Qty         int         '@Quantity')
    

    So, you can use INSERT .. SELECT FROM OPENXML statement to insert this data to DB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 300k
  • Answers 300k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Working for OP: $host = parse_url($url, PHP_URL_HOST); The version of… May 13, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer Use exslt, these extensions are available for most XSLT processors.… May 13, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer Ah, it seems I was looking in the wrong place.… May 13, 2026 at 7:56 pm

Related Questions

I looked around the site and the questions I found relating to this subject
I know this is a basic question, but I can't seem to find an
First off let me apologize to the SO community for coming to you with
I apologize for the subjectiveness of this question, but I am a little stuck

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.