Solved

Import an XML file into a SQL Database

Posted on 2003-12-02
2
563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Assisted Solution

by:TheAvenger
TheAvenger earned 50 total points
ID: 9862265
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
ID: 9862809
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

622 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