Thursday, February 9, 2012

ASP.NET +Inserting data from xml in SQL Server Database table from ASP.NET

hi

I want to read data from XML file and insert that data from XML file into the Database Table From ASP.NET page.

plz give me the code to do this using DataAdapter.Update(ds)

Hi There,

Below is a simple way to read xml data and update xml datatable to SQLserver database. ( Run a loop if you have multiple table to update )

DataSet dsXML =newDataSet();

dsXML.ReadXml(@."c:\XMLPath\file.xml");

if ( dsXML.Tables.Count > 0 )if ( dsXML.Tables[0].Rows.Count > 0 )

{

// Select table structure to dataadapter

OleDbDataAdapter dataAdapter =newOleDbDataAdapter("SELECT * FROM [" + dsXML.Tables[0].TableName +"] WHERE 1 = 2","YourConnectionString");

// Use dataadapter to update to readed xml data

dataAdapter.Update(dsXML.Tables[0]);

dataAdapter.Dispose();

}

}

No comments:

Post a Comment