Anirudh’s Weblog


Storing XML file’s data in SQL through Store Procedure
April 19, 2010, 11:47 am
Filed under: ASP.NET, SQL, XML | Tags: , , ,

CREATE PROCEDURE [dbo].[Student]
– Add the parameters for the stored procedure here
@studentlXML XML
AS
BEGIN
– SET NOCOUNT ON added to prevent extra result sets from
– interfering with SELECT statements.
SET NOCOUNT ON;

— Insert statements for procedure here
Declare @CountHandler int
Exec SP_XML_PrepareDocument @CountHandler OUTPUT,@studentlXML
INSERT INTO tblStudent –Table name where we have to save xml data
SELECT * FROM OPENXML(@CountHandler,”/friends/friend”,2)
WITH tblStudent
Exec SP_XML_RemoveDocument @CountHandler
END
END

NOTE: @studentlXML is a xml file can be passed as a string or file
friends is the parent node of xml and friend is a node under friends node, which will be excluded and rest nodes will be treated as column. Please note that node name should be exactly same as column name in table tblStudent

Advertisement

Leave a Comment so far
Leave a comment



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s



Follow

Get every new post delivered to your Inbox.