locked
Insert XML Data into SQL Server Table RRS feed

  • Question

  • User2103817411 posted

    Hi all, 

    I just need some ideas from you guys. Im using web request a get data in an xml format which displaying xml data in console. All i need to do is to insert the data that's displaying in the console to an sql server table. Please how can i go about this?

    Thanks 

    Wednesday, December 10, 2014 10:53 AM

Answers

  • User-802546231 posted

    Do you just want to save the XML response? SQL Server has a data type of XML so you can use a field with this data type to store it

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 10, 2014 11:17 AM
  • User-271186128 posted

    Hi ibcent2003,

    As Dr. Acula said, SQL Server contains XML data type, you could use it. Like this.

                    using (SqlCommand command = new SqlCommand("INSERT INTO [dbo].[xmldata] ([xmldata]) VALUES(@xml)", connection))
                    {
                        command.Parameters.AddWithValue("@xml", doc.InnerXml);
                        command.ExecuteNonQuery();
                    }

    More details, please see: http://forums.asp.net/t/1903014.aspx?XML+Upload

    Besides, here are some good articles, perhaps they can help you.

    Insert (Upload) XML file Data into SQL Table using Stored Procedure in ASP.Net using C#, VB.NET:

    http://www.aspsnippets.com/Articles/Insert-Upload-XML-file-Data-into-SQL-Table-using-Stored-Procedure-in-ASPNet-using-C-VBNET.aspx

    How to insert data from XML to database:

    http://csharp.net-informations.com/xml/xml-to-database.htm

    Best Regards,
    Dillion

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 11, 2014 7:33 AM

All replies

  • User-802546231 posted

    Do you just want to save the XML response? SQL Server has a data type of XML so you can use a field with this data type to store it

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 10, 2014 11:17 AM
  • User2103817411 posted

    Yea i want to store the response. and i dont know if can extract node by node instead of storing the whole xml response in a table.

    Wednesday, December 10, 2014 11:29 AM
  • User-271186128 posted

    Hi ibcent2003,

    As Dr. Acula said, SQL Server contains XML data type, you could use it. Like this.

                    using (SqlCommand command = new SqlCommand("INSERT INTO [dbo].[xmldata] ([xmldata]) VALUES(@xml)", connection))
                    {
                        command.Parameters.AddWithValue("@xml", doc.InnerXml);
                        command.ExecuteNonQuery();
                    }

    More details, please see: http://forums.asp.net/t/1903014.aspx?XML+Upload

    Besides, here are some good articles, perhaps they can help you.

    Insert (Upload) XML file Data into SQL Table using Stored Procedure in ASP.Net using C#, VB.NET:

    http://www.aspsnippets.com/Articles/Insert-Upload-XML-file-Data-into-SQL-Table-using-Stored-Procedure-in-ASPNet-using-C-VBNET.aspx

    How to insert data from XML to database:

    http://csharp.net-informations.com/xml/xml-to-database.htm

    Best Regards,
    Dillion

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 11, 2014 7:33 AM