Solved

Import an XML file into a SQL Database

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Suggested Courses

734 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