how to insert record in xml

Posted by Subhadip under ASP.NET on 3/22/2011 | Points: 10 | Views : 2400 | Status : [Member] | Replies : 2
i want to know that how to insert record in database using xml in asp.net ?????????????????????




Responses

Posted by: Sashys on: 4/19/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,
Let me confirm my understanding on your problem first.
I assume that you are trying to send an xml with set of values to the database, where the sql stored procedure will read and insert the xml values in to the Table. If so, pls refer the code and explanation.

Assume i have below Xml:
<items>

<emp id="1"></item>
<emp id="9"></item>
<emp id="10"></item>
<emp id="11"></item>
<emp id="12"></item>
<emp id="13"></item>
</items>
Create procedure usp_InsertmyXml
@XMLDOC varchar(8000)
AS
declare @xml_hndl int

--To prepare the XML Document
exec sp_xml_preparedocument @xml_hndl OUTPUT, @XMLDOC

--To insert into a table
Insert Into Emptable
(
empid
)
Select
xmlid
From
OPENXML(@xml_hndl, '/items/emp', 1)
With
(
xmlid int '@id'
)


Hope this example will help you!!

Sasikumar .M

Subhadip, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 4/19/2011 [Member] Starter | Points: 25

Up
0
Down
hi...if you want to insert the xml data into database.....then try this link..
http://vbdotnetaddict.blogspot.com/2011/02/how-to-insert-xml-data-into-sql.html

Subhadip, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response