Read XML Data Into DataSet In Asp.Net C# VB.NET
In this code example i'm explaining how to Read XML Data Into DataSet Using C# And VB.NET In Asp.Net.
For this i have placed one GridView on the aspx page to display after reading Data from XML File on server in Click Event of Read Button.
XML File contains firstname, lastname and location sub elements under employee element.
C# CODE
01using System.Data;02using System.IO;03protected void btnReadXmlFile_Click(object sender, EventArgs e)04 {05 string filePath = Server.MapPath("~/Employees.xml");06 DataSet dsData = new DataSet();07 //If you don't want to read through FileStream then comment below line08 FileStream fsReadSchema = new FileStream(filePath, FileMode.Open);09 dsData.ReadXml(fsReadSchema);10 fsReadSchema.Close();11 GridView1.DataSource = dsData;12 GridView1.DataBind();13 }VB.NET CODE
01Protected Sub btnReadXmlFile_Click(sender As Object, e As EventArgs)02 Dim filePath As String = Server.MapPath("~/Employees.xml")03 Dim dsData As New DataSet()04 'If you don't want to read through FileStream then comment below line05 Dim fsReadSchema As New FileStream(filePath, FileMode.Open)06 dsData.ReadXml(fsReadSchema)07 fsReadSchema.Close()08 GridView1.DataSource = dsData09 GridView1.DataBind()10End Sub

0 comments:
Post a Comment