Can someone provide an example of how to send an xml from C# to SQL Server, and then loop on the xml in the stored procedure that got it, and update or enter line by line.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Check out the three-part series on SQL XML on 15seconds: http://www.15seconds.com/Issue/050803.htm.
I would personally use the SQL XQuery functions to shred apart your XML into bits and pieces and store those in SQL Server.
If you have something like:
you can write something like:
So basically, the
.nodesfunction shreds your XML into a “pseudo-table”Data.Person– each<person>entry becomes one row in the table.With the
.value()function, you can extract single values from those shredded XML nodes. You now have a bunch of varchar(20) fields, that can be e.g. inserted into a table.This method works well if your XML is fairly small (a few hundred entries). If you have huge XML files, you might want to investigate other methods, such as XML Bulkload.