Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read from an xml and store related data to DB

Status
Not open for further replies.

RaulMA

Programmer
Apr 4, 2006
19
US
How can I store data from an xml file to a sql server data base?

Thanks
 
Hi,

Methodology I have used in the past is as follows:

Load the XML file into an System.XML.XMLDocument Object.

Create an System.Data.SqlConnection
Create an System.Data.SqlCommand

Depending on how you want to put the data into the database use either a Embedded SQL statement or call a stored procedure

Loop through the XML elements / nodes using a "for" or "foreach" loop passing the data from the XMLNodes Attributes to the SqlCommand.Parameters and finally calling the SqlCommand.ExecuteNonQuery() member to execute the SQL Statement.

This is the basic methodology - code examples can be found at as there are many ways in which to load XML files etc.

Hope this is of some help... [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top