how to transfer xml file data to database using SqlDataAdapter Update method

Posted by Imteyazkhan374 under C# category on | Points: 40 | Views : 1657
Sometimes we need to transfer the xml file information to the database. Here I have developed code which will transfer xml file information to the database using SqlDataAdater update method.

1. Very first you need to create a xml file like this:
<?xml version="1.0" standalone="yes"?>

using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Xml;
namespace XML_file_to_database_new
public partial class Form1 : Form
public Form1()
DataSet sqlds;
DataSet xmlds;
SqlDataAdapter da;

private void btnupdate_Click(object sender, EventArgs e)
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True;");
da = new SqlDataAdapter(new SqlCommand("select * from detail_student", con));
SqlCommandBuilder cmdbilder = new SqlCommandBuilder(da);
sqlds = new DataSet();
xmlds = new DataSet();

for (int i = 0; i < xmlds.Tables[0].Rows.Count; i++)
DataRow dr;
dr = sqlds.Tables[0].NewRow();
dr[0] = Convert.ToString(xmlds.Tables[0].Rows[i].ItemArray[0]);
dr[1] = Convert.ToInt32(xmlds.Tables[0].Rows[i].ItemArray[1]);
dr[2] = Convert.ToString(xmlds.Tables[0].Rows[i].ItemArray[2]);


dataGridView1.DataSource = sqlds.Tables[0];

Comments or Responses

Login to post response