Click here to Skip to main content
Click here to Skip to main content

XML Reader - Import data from XML file to MSSQL table

, 23 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Import data from a bulky XML file to a MSSQL table.


This document describes a simple way of importing data from XML file to a MSSQL table. People involving in data coversion activities can easily use this application to convert their bulky MXL inputs.

Screenshot - Reader.jpg


The sample project can load an XML file and read it and show it in a data grid view. Then you can write dataset to a MSSQL table. In this article I am describing the way of writing the dataset to a MSSQL table. But you can write the dataset to any type of Databse table.

Using the code

The sample application uses ReadXml method of dataset to read a XML file.

Then you can save these data to a MSSQL data table.

SqlConnection myconnection = new SqlConnection();

SqlDataAdapter myda=new SqlDataAdapter();

myconnection.ConnectionString = "Data Source=DHANUSHKA\\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True";

string strsql = "INSERT INTO Data(name, age)VALUES(@name,@age)";


SqlCommand myinsertcommand = new SqlCommand(strsql, myconnection);

myinsertcommand.Parameters.Add("@name", SqlDbType.VarChar, 15, "name");

myinsertcommand.Parameters.Add("@age", SqlDbType.VarChar, 15, "age");

myda.InsertCommand = myinsertcommand;



When adding parameters to the insert command of data adapter @name and @age are tag names in XML file and "name" and "age" are column names in MSSQL data table.

Points of Interest

One of my friends asked me that he wants to import data from a bulky XML file to a MSSQL table. After few minutes of effort I came up with a nice simple application having few lines of code. And also my friend next to my block, Chamin, helped me on this.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Sri Lanka Sri Lanka
I am Dhanushka Weedagama and I work at Pearson Lanka (pvt) Ltd as a senior software engineer.

Comments and Discussions

GeneralXML Reader Pinmemberabdellaoui13-Aug-08 5:42 
Hello DhanuWeedagam,

beautiful article what you wrote. I'm still beginner in this area, perhaps you can help me!
I have a XML file with more than 500 Data, and I would like to insert this Data into an Oracle table.

Where should my code for the Oracle look insert command, and where should I write

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Oracle.DataAccess.Client;

namespace XmlReader
static class Program
/// The main entry point for the application.

static void Main()
OracleConnection con = new OracleConnection();
con.ConnectionString = "Data Source .....";

OracleCommand insert = new OracleCommand();
insert.CommandText = "insert into Data (Fgroup, Name, Password, SID) values (:Fgroup, :Name, :Password, :Sid)";

OracleDataAdapter da = new OracleDataAdapter();
da.InsertCommand = insert;

insert.Parameters.Add(":FGroup", OracleDbType.Blob, 20, "FGroup");
insert.Parameters.Add(":Name", OracleDbType.Varchar2, 20, "Name");
insert.Parameters.Add(":Password", OracleDbType.Raw, 100, "Password");
insert.Parameters.Add(": SID", OracleDbType.Raw, 64, " SID");



Application.Run(new Form1());

This is a part of my XML file:



think it is correct?

Questionneed help in reading this type of xml schema. Pinmember.Net Proffesional9-Oct-07 2:25 
AnswerRe: need help in reading this type of xml schema. Pinmemberwilliam01230-Oct-09 1:08 
QuestionXML File? PinmemberManjit Dosanjh25-Aug-07 1:07 
AnswerRe: XML File? PinmemberDhanuWeedagam26-Aug-07 18:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 23 Aug 2007
Article Copyright 2007 by DhanuWeedagam
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid