XML and DataSets

A DataSet stores data that is obtained from a data source.The datasource can be classified as two.
1.Relational Database
2.XML Document

Dataset also can also be classified as

Typed Dataset-A typed dataset is derived from a dataset class and has an associated XML Schema.
UnTyped Dataset-An untyped dataset doesnot have an associated XML Schema.

The XML Schema contains all the information about tables,constraints,and relations that will need to validate an XML document.All these information is stored in the XSD (SML Schema Definition) file.

Role of .Net Framework …. The .Net Framework uses XSD to generate Data for Dataset.

XML – DATASET Methods

GetXML - Enables you to retrieve the XML representation of the data stored in a dataset in to a string
ReadXML - Reads the XML data and schema in to the Dataset
ReadXMLSchema - Reads the XML Schema in to the dataset
WriteXML - Write the data of Dataset in to a XML file
WriteXMLSchema - Write the data in the dataset in to XML Schema

Role of ADO.Net …. ADO.Net is used to transfer data between XML files and Dataset.

Write XML data from a DataSet

Visual Basic .NET

Dim con as new SqlConnection(“server={servername};database={dbname};uid={user};pwd={password}”)
Con.open()
Dim ada as new SqlDataAdapter(“select * from Items”,con)
Dim dt as new DataSet()
Ada.fill(dt)
Ds.WriteXML(“items.xml”, XmlWriteMode.WriteSchema)

Visual C#

SqlConnection con=new SqlConnection(“server={servername};database={dbname};uid={user};pwd={passwrd}”);
con.Open();
SqlDataAdapter ada=new SqlDataAdapter(“select * from Items”,con);
Dataset dt=new Dataset();
Ada.Fill(dt);

Dt.WriteXML(“Items.xml”, XmlWriteMode.WriteSchema);

 

Sample Code : Validate a User using XML and ASP.Net