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
VB.NET CODE
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
01
using
System.Data;
02
using
System.IO;
03
protected
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 line
08
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
01
Protected
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 line
05
Dim
fsReadSchema
As
New
FileStream(filePath, FileMode.Open)
06
dsData.ReadXml(fsReadSchema)
07
fsReadSchema.Close()
08
GridView1.DataSource = dsData
09
GridView1.DataBind()
10
End
Sub
0 comments:
Post a Comment