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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:15:00+00:00 2026-05-31T06:15:00+00:00

I’m new to C# and have been working on learning database’s. Currently I’m trying

  • 0

I’m new to C# and have been working on learning database’s. Currently I’m trying to import data from a XML document that has items stored as follows:

   <CityData>
        <City>Ada</City>
        <County>Olmsted</County>
        <AreaCode>507</AreaCode>
        <Founded>1900</Founded>
        <CityWebSite>www.adacity.com</CityWebSite>
        <Population>1200</Population>
        <Zipcode>56996</Zipcode>
        <ZipcodeMax>57656</ZipcodeMax>
    </CityData>

I’m trying to save each data collection to a different row in a SQL Express database. I’ve been able to store other information in the database, I just don’t know how to do this with a XML document. The database is stored locally on my machine along with the C# program I’m writing. I have a new table with columns named and ordered like the XML documents schema. The tutorials I’m finding online are for .asp programs. Has anyone ever done this? This is a C# Forms Program.

  • 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-31T06:15:01+00:00Added an answer on May 31, 2026 at 6:15 am

    This will do your job. please make sure to replace filePath\fileName.xml with full path to the xml and change /dataroot/CityData (at the bottom) as per your xml. Also sql should be able to access the file.

    Declare @xml XML
    
    Select  @xml  = 
    CONVERT(XML,bulkcolumn,2) FROM OPENROWSET(BULK 'filePath\fileName.xml',SINGLE_BLOB) AS X
    
    SET ARITHABORT ON
    
    Insert into [YourTableName] 
            (
                City,County,AreaCode,Founded,CityWebSite,[Population],Zipcode,ZipcodeMax
            )
    
        Select 
            P.value('City[1]','VARCHAR(100)') AS City,
            P.value('County[1]','VARCHAR(100)') AS County,
            P.value('AreaCode[1]','VARCHAR(100)') AS AreaCode,
            P.value('Founded[1]','VARCHAR(100)') AS Founded,
            P.value('CityWebSite[1]','VARCHAR(100)') AS CityWebSite,
            P.value('Population[1]','VARCHAR(100)') AS Population,
            P.value('Zipcode[1]','VARCHAR(100)') AS Zipcode,
            P.value('ZipcodeMax[1]','VARCHAR(100)') AS ZipcodeMax,
    
        From @xml.nodes('/dataroot/CityData') PropertyFeed(P)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a reasonable size flat file database of text documents mostly saved in

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.