Save XML directly to Database with C#

前端 未结 1 1858
时光取名叫无心
时光取名叫无心 2021-01-24 02:02

Here is a part of my xml file


  
    Australia
    1
    

        
相关标签:
1条回答
  • 2021-01-24 02:17

    SQL Server 2005+ has a native XML datatype, if you create a column, you can simply do an insert into that column, here is an insert similar to yours, this table's second column's datatype is xml

    INSERT INTO docs VALUES (1, '<book genre="security"
    publicationdate="2002" ISBN="0-7356-1588-2">
       <title>Writing Secure Code</title>
       <author>
          <first-name>Michael</first-name>
          <last-name>Howard</last-name>
       </author>
       <author>
          <first-name>David</first-name>
          <last-name>LeBlanc</last-name>
       </author>
       <price>39.99</price>
    </book>')
    INSERT INTO docs VALUES (2, 
    '<doc id="123">
        <sections>
       <section num="1"><title>XML Schema</title></section>
       <section num="3"><title>Benefits</title></section>
       <section num="4"><title>Features</title></section>
        </sections>
    </doc>')
    
    0 讨论(0)
提交回复
热议问题