NetProgrammingHelp.com
Asp.Net,C#,Ajax,Sql server,silverlight,Javascript codes exambles articles,Programming exambles

Recent Posts

  • How to declare/use global constants (enum’s) in javascript ajax function
  • Silverlight Data Binding OneWay TwoWay Asp.Net C# XAML
  • Accessing Executing Running Stored Procedure/Function/Package Using Linq Silverlight Xaml
  • Creating/Developing Silverlight Data Driven Applications Using Wcf Linq Asp.Net C#
  • Deploying Manually Publish XBAP Wpf Browser Application in IIS Asp.Net C# XAML
  • Creating Server and client using remoting asp.net c#
  • Create/Build wcf autocomplete/autoextender textbox using database linq c# asp.net
  • Essentials for Creating/Developing/Programming silverlight project tools wpf xaml
  • Working with xml data type variable sql server 2008 asp.net c#
  • Encrypting Stored Procedure sql server 2008 asp.net c#
  • How to Insert a XML Data into Sql Table Using OPENXML SQL SERVER

    Posted by James Categorized Under: SQL SERVER/ORACLE one Commented

    Introduction:
    In this article, i am going to explain about how to insert a data into sql table using OpenXml/Sql Server.

    Main:

    OPENXML provides a rowset view over an XML document.OPENXML allows you to read xml strings,

    syntax for OPENXML,

    OPENXML(idoc int[input],rowpattern varchar[input],[flags byte[input])
    WITH (SchemaDeclaration | TableName)]
     
    DECLARE @idoc int
    DECLARE @doc varchar(8000)
    SET @doc ='<ROOT><EMP>
    <id>1</id>
    <name>James</name>
    <age>32</age>
    </EMP>
    <EMP>
    <id>2</id>
    <name>Chris</name>
    <age>42</age>
    </EMP>
    <EMP>
    <id>3</id>
    <name>Peter</name>
    <age>23</age>
    </EMP>
    <EMP>
    <id>4</id>
    <name>Andrea</name>
    <age>12</age>
    </EMP>
    <EMP>
    <id>5</id>
    <name>Christopher</name>
    <age>75</age>
    </EMP>
    </ROOT>'
     
    --Create an internal representation of the XML document.
    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
    -- Execute a SELECT statement that uses the OPENXML rowset provider.
    Insert into EMP_Details SELECT id, name, age from 
    OPENXML (@idoc, '/ROOT/EMP',2)
    WITH (id  int, name varchar(50), age int)
     
    Select * from EMP_Details

    Conclusion:
    Hope this helps,
    Happy Coding.

    One Response to “How to Insert a XML Data into Sql Table Using OPENXML SQL SERVER ”

    1. Your web site is very fascinating,I would like to connect with u,could i sent electronic mail to you?

    Leave a Reply