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

  • SEARCH
  • Home
  • 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 8036009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:28:39+00:00 2026-06-05T02:28:39+00:00

I having XMl file I am Reading All the Xml using this code .

  • 0

I having XMl file I am Reading All the Xml using this code . But mean while I want to insert XML records to sql table,Whatever I have Read. I did not Find any Solution for that .XMl consists No of rows and how can i insert in Proper way .

       if (File.Exists(xmlpath))
          {
             try
              {
                XDocument xmlDoc = XDocument.Load(xmlpath);
                var vrresult = from a in xmlDoc.XPathSelectElements("/Parts/Part")
                               select new
                               {
                                  S  = a.Element("Section").Value,
                                   M = a.Element("Mark").Value,
                                   Q = a.Element("Qty").Value,
                                   W = a.Element("Weight").Value,
                                   RD = a.Element("databaseUpdateMark").Value

                               };
                GridView1.DataSource = vrresult;
                GridView1.DataBind();

            }
            catch (Exception ex)
            {
                Lbmsg.Text = ex.Message;
            }
            finally
            {

            }
        }
  • 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-06-05T02:28:41+00:00Added an answer on June 5, 2026 at 2:28 am

    here is one example how to use OPENXML function

    Bulk Insertion of Data Using C# DataTable and SQL server OpenXML function


    Make use of function : OPENXML (Transact-SQL) which is avialble in sql server allows you to insert data in server….

    also read : Use OPENXML to insert values from a string of XML

    Example :

    --Use OPENXML to pull records from an XML string and insert them into a database
    
    DECLARE @idoc int
    DECLARE @doc varchar (1000)
    
    --XML document
    
    SET @doc ='
    <ROOT>
        <Employee>
            <FirstName>Tom</FirstName>
            <LastName>Jones</LastName>
        </Employee>
        <Employee>
            <FirstName>Gus</FirstName>
            <LastName>Johnson</LastName>
        </Employee>
    </ROOT>'
    
    --Create an internal representation of the XML document
    --the idoc variable is set as the document handler, so we can refer to it later
    
    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
    
    -- Use the OPENXML rowset provider with an Insert
    -- @idoc lets us know which internal representation of an xml doc to use
    -- '/ROOT/Employee' shows us which node in the xml tree to work on
    -- the 2 denotes we want to use elemenet centric mapping for the values, as oppsed to attributes or a combination of both
    -- in the 'With' we specify how the output rowset will look
    
    INSERT INTO Employees (FirstName, LastName)
    SELECT *
    FROM OPENXML (@idoc, '/ROOT/Employee',2) 
    WITH (FirstName varchar(10),
    LastName varchar(20)
    )
    
    -- Clear the XML document from memory
    
    EXEC sp_xml_removedocument @idoc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using DOM to parse an xml file. And I am having trouble catching
I'm having a problem with reading and processing a xml file, which I cannot
I've been having some issues reading an XML file in my 'res' folder and
I am having problems with malformed XML in my phing build file. I want
I'm having troubles reading values from an xml file. Here is the xml file:
I am having a difficult time reading an XML file with Cdata inside. in
I am having troubles reading XML, I followed this tutorial , and generated the
I am having a xml file and i am reading the data from that
I am reading in an XML file and using it to populate a WPF
I need some help using Linq to xml, I've been reading online articles but

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.