Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. XML Save and Load to SQL Server 2005 database.

XML Save and Load to SQL Server 2005 database.

Scheduled Pinned Locked Moved Database
databasesql-serversysadminxmltutorial
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ashwath1979
    wrote on last edited by
    #1

    Hi All, Please tell me how to do the following: XML save and load of data to SQL Server 2005 database? Thanking you in advance, Regards, Ashwath Hegde.

    H N 2 Replies Last reply
    0
    • A ashwath1979

      Hi All, Please tell me how to do the following: XML save and load of data to SQL Server 2005 database? Thanking you in advance, Regards, Ashwath Hegde.

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Look at the MSDN documentation for either DataSet or DataTable. Both of them have ReadXml and WriteXml methods.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      1 Reply Last reply
      0
      • A ashwath1979

        Hi All, Please tell me how to do the following: XML save and load of data to SQL Server 2005 database? Thanking you in advance, Regards, Ashwath Hegde.

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        You can have your column type as XML and SqlDbType[^] enum supports XML type. You can write something like,

        using (SqlConnection conn = /* ... */)
        using (SqlCommand cmd = new SqlCommand("insert into your_table VALUES(@xml_content)", conn))
        {
        cmd.Parameters.Add("@xml_content", SqlDbType.Xml).Value = new SqlXml(reader);
        // other code
        }

        SqlXml can take a Stream or a XmlReader instance. For reading data, work with the SqlDataReader.GetSqlXml()[^] method. SqlXml.ReadOuterXml() will give you a string representation of the XML. :)

        Navaneeth How to use google | Ask smart questions

        A 1 Reply Last reply
        0
        • N N a v a n e e t h

          You can have your column type as XML and SqlDbType[^] enum supports XML type. You can write something like,

          using (SqlConnection conn = /* ... */)
          using (SqlCommand cmd = new SqlCommand("insert into your_table VALUES(@xml_content)", conn))
          {
          cmd.Parameters.Add("@xml_content", SqlDbType.Xml).Value = new SqlXml(reader);
          // other code
          }

          SqlXml can take a Stream or a XmlReader instance. For reading data, work with the SqlDataReader.GetSqlXml()[^] method. SqlXml.ReadOuterXml() will give you a string representation of the XML. :)

          Navaneeth How to use google | Ask smart questions

          A Offline
          A Offline
          ashwath1979
          wrote on last edited by
          #4

          Can you please give the complete code snippet so that i can understand fully.

          N 1 Reply Last reply
          0
          • A ashwath1979

            Can you please give the complete code snippet so that i can understand fully.

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            ashwath1979 wrote:

            Can you please give the complete code snippet so that i can understand fully.

            That is laziness. What have you tried and where you are stuck?

            Navaneeth How to use google | Ask smart questions

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups