Solved

Import an XML file into a SQL Database

Posted on 2003-12-02
2
541 Views
Last Modified: 2010-04-16
I have an XML file of a database.  How do I convert or import this data into my sql database.  I have some code usin SQLXMLBulkLoad but it is in VB any body have any using C#
0
Comment
Question by:lyptus
2 Comments
 
LVL 20

Assisted Solution

by:TheAvenger
TheAvenger earned 50 total points
Comment Utility
You can translate the code of VB.NET to C# very easily yourself or for example here:

http://www.ellkay.com/ConvertVB2CSharp.htm
0
 
LVL 6

Accepted Solution

by:
townsma earned 200 total points
Comment Utility
I am assuming that it is the data that you wish to import and not the structure also. If this is the case you can use the ReadXML method of the dataset object to read you data in.  Below is a snippet of code that may help.

             //  Create a dataset an populate it with the structure of the table the data should be imported into.
             DataSet oDS = new DataSet("Select * from tablename");

              // Read the XML document back in.
              //Create new FileStream to read schema with. sFileName contains the name, and path, of the XML file to be imported.
              FileStream fsReadXml = new System.IO.FileStream(sFileName, System.IO.FileMode.Open);

              // Create an XmlTextReader to read the file.
              System.Xml.XmlTextReader myXmlReader = new System.Xml.XmlTextReader(fsReadXml);

              //Finally read the xml data into the dataset.
              oDS.ReadXml(myXmlReader);

              // Close the XmlTextReader
              myXmlReader.Close();


Hope this helps.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now