The disconnected data access model of ADO.NET is centered on DataSets. DataSets are the core of ADO.NET architecture and represent an in memory representation of the database. They can be used with a wide variety of data sources and contain one or more DataTable objects. These DataTable objects in turn comprise of one or more DataRows and DataColumns. While the DataTable object represents every table within a DataSet; the DataColumn and the DataRow objects represent the columns and rows within a DataTable. The DataSet class provides a seamless support for XML. Using XML, we can use the DataSet class in ADO.NET to perform the CRUD (Create, Read, Update and Delete) operations without an underlying database to store the data. This article discusses how we can use DataSets and XML – considered by many as a perfect combination to perform the CRUD operations devoid of any underlying database to hold data.
What are DataSets?
A DataSet is in effect an in-memory representation of cached, disconnected data that is available as a as a collection of tables, relationships, constraints, etc. In other words, a DataSet is actually an in-memory representation of the entire database along with its tables and relationships.
The DataSet class is contained in the System.Data namespace in ADO.NET. The DataSet class has the ability to represent itself as XML upon request or when you pass it through the tiers or components of an application.
The primary advantage in using DataSets in applications is its disconnected approach that enables data to be transferred across application boundaries. The primary disadvantage of using DataSets however that is it consumes large amount of memory that is particularly a nightmare if your DataSet contains high volume of data. Hence, it becomes detrimental to the application’s performance when the DataSet contains large amount of data due to excessive consumption of memory.
DataSet and XML – A perfect match
Before we delve deep any further, let us have a recap of XML. What is XML and why is it so useful? Extensible Markup Language (XML) is a simple, platform independent, flexible meta-markup language that provides a format for storing structured data and is great for efficient exchange of data across the internet. XML has rapidly gained wide popularity and the enterprise applications the world over are using XML as the primary format for data exchange across the globe.
The salient features of this language are:–
- Support for UNICODE
- Hierarchical structure
- Platform Independent
- Present in human readable format
- Can support even complex data structures
Now that we have had a quick tour of XML, let us discuss the support for XML provided by the DataSet class in ADO.NET.
The DataSet class in ADO.NET contains a lot of methods that provide XML support. The following are some of the most important methods of this class:–
- The ReadXml Method
- The ReadXmlSchema Method
- The GetXml Method
- The GetXmlSchema Method
- The WriteXml Method
- The WriteXmlSchema Method
While the ReadXML, GetXML and WriteXML methods deal with the data as XML representation devoid of any schema, the ReadXMlSchema, WriteXMLSchema and the GetXMLSchema methods represent the schema only. These methods would become much clear as we move on to the next section where working (for CRUD operations) with DataSet instances and XML has been illustrated. //break//
Working with DataSet and XML
This section discusses how we can perform the CRUD operations using DataSet and XML as the database to store the data.