Solved

Import an XML file into a SQL Database

Posted on 2003-12-02
2
549 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Diagnostics with Net and Net.Sockets 2 30
Install Problem 13 32
PrintingFoundIt(Almost!(Damn!)) 1 27
What Does This C# Code Block Do? 5 34
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

825 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