Google News
logo
ADO.NET Interview Questions
* ADO.NET stands for Active Data Object, it is a part of the .NET Framework by Microsoft. ADO.NET framework provides a set of classes that are used to handle data communication with data sources such as XML files and databases (such as SQL, Oracle, MySQL, MS Access, etc.).

* ADO.NET can separate mechanisms for data connectivity, data access, and data manipulation.

* It has introduced the disconnected architecture, in which data can be stored in a DataSet. ADO.NET has providers for database connection, commands for execution, and result retrieval.

* The ADO.NET classes are stored in the DLL named System.Data.dll.

* Various applications like ASP.NET applications, console applications, windows applications, etc., will use ADO.NET for database connection, command execution, and retrieval of data.

ADO.NET provides mainly the following two types of architectures :
 
  * Connected Architecture.
  * Disconnected Architecture.
Following namespaces are used to connect to Database.
 
* The System.Data namespace.
* The System.Data.OleDb namespace  –  A data provider used to access database such as Access, Oracle, or SQL.
* The System.Data.SQLClient namespace – Used to access SQL as the data provider.
Below Data Providers are used in ADO.NET framework.
 
.NET Framework Data Provider for SQL Server – A Data provider that provides access to Microsoft SQL Server 7.0 or later version and it uses the System.Data.SqlClient namespace.

.NET Framework Data Provider for OLE DB – A Data Provider that provides access to any database exposed by using OLE DB and it uses the System.Data.OleDb namespace.

.NET Framework Data Provider for ODBC – A Data Provider that provides access to any databases exposed by using ODBC and It uses the System.Data.Odbc namespace.

.NET Framework Data Provider for Oracle – A Data Provider that provides access to Oracle database 8.1.7 or later versions and it uses the System.Data.OracleClient namespace.
The two essential objects of ADO.Net are:
 
* DataReader
* DataSet
The DataReader object of ADO.NET is used to provide the access of data from a specified data source. It contains classes to sequentially read data from a data source like Oracle, MS Access, SQL Server, etc.
ADO.NET components categorized in three modes: disconnected, common or shared and the .NET data providers.
 
The disconnected components build the basic ADO.NET architecture. You can use these components (or classes) with or without data providers. For example, you can use a DataTable object with or without providers and shared or common components are the base classes for data providers. Shared or common components are the base classes for data providers and shared by all data providers. The data provider components are specifically designed to work with different kinds of data sources. For example, ODBC data providers work with ODBC data sources and OleDb data providers work with OLE-DB data sources.
 
Figure represents the ADO.NET components model and how they work together : 
Reprasents The ADO
A Dataset is set to be collection of data with a tabular column representation. Each column in the table represents a variable and the row represents to value of a variable. This Dataset object can be obtained from the database values.
Object pooling is nothing but a repository of the objects in memory which can be used later. This object pooling reduces the load of object creation when it is needed. Whenever there is a need of object, object pool manager will take the request and serve accordingly.
Connection pooling consists of database connection so that the connection can be used or reused whenever there is request to the database. This pooling technique enhances the performance of executing the database commands. This pooling definitely reduces our time and effort.
These are the main differences between ADO and ADO.NET:

ADO ADO.NET
ADO have recordset. ADO.NET have data adopter and data set.
The objects of ado communicate in binary mode. It uses XML for passing the data.
It supports mostly connection oriented models. It works in disconnected manners.
It derives information about data implicitly at runtime based on metadata, so it is a costly process. It uses known metadata at design time, so it provides better runtime performance and more consistent runtime behavior.
It allows only client-side cursors. It supports both client side and server side cursors.
* ADO.NET provides inbuilt classes to make a connection with databases like Oracle, SQL Server, MySQL, MS Access, etc.

* ADO.NET provides inbuilt classes for data manipulation operations like Insert, Update, Delete and Select data.

* Provide a function to combine data from different data sources.

* Disconnect data architecture for better performance.
A DataAdapter is used to access data from a data source by functioning as a bridge between DataSet and a data source. DataAdapter class includes an SQL command set and a database connection. It is helpful to fill the DataSet and resolve changes to the data source.

The DataAdapter will make use of the Connection object that belongs to the .NET Framework data provider for connecting with a data source. Along with that, it will also use Command objects to retrieve data from the data source as well as to resolve changes to the data source.

DataAdapter properties that permit the user to control the database are the Select command, Update command, Insert command, and Delete command.

Example code for the usage of DataAdapter :
using System;  
using System.Data.SqlClient;  
using System.Data;  
namespace DataAdapterExample  
{  
    public partial class DataAdapterDemo : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            using (SqlConnection conn = new SqlConnection("data source=.; database=items; integrated security=SSPI"))  
            {  
                SqlDataAdapter da = new SqlDataAdapter("Select * from items", conn);  
                DataSet s = new DataSet();  
                da.Fill(s);  
                GridView1.DataSource = s;  
                GridView1.DataBind();  
            }  
        }  
    }  
}  ​
Here, DataAdapter will receive the data from the items table and fill the DataSet, which will be later used to display the information retrieved from the items database.
ADO.NET(Active Data Objects) ASP.NET(Active Server Pages)
ADO.NET is a Library within the .NET framework. ASP.NET is a Framework.
It is a technology useful for accessing data from databases. It is a technology useful for the creation of dynamic web pages.
Here, data can be converted into XML format. Here, We can write our code into VB.Net, C#, ASP.Net, etc.
It is used to develop reliable and scalable database applications with high performance for client-server applications. It is used to create dynamic web pages, web applications, websites, and web services.
DataSet can be said as a collection of database tables(row and column format) that holds the data. There are two types of DataSet in ADO.NET. They are :
 
Typed DataSet : A typed DataSet is derived from the DataSet base class and can be created by selecting the DataSet option provided by Visual Studio. It will be created as an XML schema(.xsd file) that contains DataSet structure information such as rows, columns, and tables. Data from the database is moved into a dataset and from the dataset to another component in the XML format.

Untyped DataSet : Untyped DataSet does not have an associated XML schema with it. Users are supposed to add columns, tables, and other elements to it. Properties can be set during design time or can add them during run time.

Example program for the usage of DataSet :
using System;  
using System.Data.SqlClient;  
using System.Data;  
namespace DataSetDemo  
{  
    public partial class DataSetExample : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            using (SqlConnection conn = new SqlConnection("data source=.; database=employee; integrated security=SSPI"))  
            {  
                SqlDataAdapter da = new SqlDataAdapter("Select * from employee", conn);  
                DataSet d = new DataSet();  
                da.Fill(d);  
                GridView1.DataSource = d;  
                GridView1.DataBind();  
            }  
        }  
    }  
}​

 

Here, DataSet will be filled by DataAdapter that receives data from the employee table. This DataSet will be used to display the information received from the employee database.
DataTable DataSet
DataTable consists of a single database table that is placed within a memory. DataSet consists of a collection of multiple database tables which is placed within a memory.
It has a row and column collection. It has a database table collection.
It allows fetching only a single TableRow at a time. It allows fetching multiple TableRows at a time.
It is a single database table, so there will not be any relation with other tables. It represents a collection of DataTable objects, so there might be a relation between them to obtain a particular result.
In this, DataSource objects are not serialized. In this, DataSource objects are serialized.
UniqueConstraint and ForeignKeyConstraint objects are not available enforcing data integrity. UniqueConstraint and ForeignKeyConstraint objects are available for enforcing data integrity.
* DataTable represents a single table in a database.
* In this show row and column.
* DataSet is a collection of data tables.
* In this store data record.

DataTable representation in .aspx.cs code,
protected void BinddataTable()
{
    SqlConnection con = new SqlConnection("your database connection string");
    con.Open();
    SqlCommand cmd = new SqlCommand("Write your query or procedure", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    grid.DataSource = dt;
    grid.DataBind();
}
CommandBuilder helps you to generate update, delete, and insert commands on a single database table for a data adapter. Similar to other objects, each data provider has a command builder class. The OleDbCommandBuilder, SqlCommonBuilder, and OdbcCommandBuilder classes represent the CommonBuilder object in the OleDb, Sql, and ODBC data providers.
 
Creating a Command Builder Object :
 
Creating a CommonedBuider object is pretty simply. You pass a DataAdapter as an argument of the CommandBuilder constructor. For example,
// Create a command builder object
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
A DataView enables you to create different views of the data stored in a DataTable, a capability that is often used in data binding applications. Using a DataView, you can expose the data in a table with different sort orders, and you can filter the data by row state or based on a filter expression. A DataView provides a dynamic view of data whose content, ordering, and membership reflect changes to the underlying DataTable as they occur. This is different from the Select method of the DataTable, which returns a DataRow array from a table per particular filter and/or sort order and whose content reflects changes to the underlying table, but whose membership and ordering remain static. The dynamic capabilities of the DataView make it ideal for data-binding applications.
 
How we can create a DataView
 
There are two ways to create a DataView. You can use the DataView constructor, or you can create a reference to the DefaultView property of the DataTable. The DataView constructor can be empty, or will also take either a DataTable as a single argument, or a DataTable along with filter criteria, sort criteria, and a row state filter.
DataView custDV = new DataView(customerDS.Tables["Customers"],
"Country = 'USA'",
"ContactName",
DataViewRowState.CurrentRows);
DataView custDV = customerDS.Tables["Customers"].DefaultView;
ExecuteScalar Method :
 
The ExecuteScalar method of the SqlCommand object is useful for retrieving a single value from the database. In our example, we need to retrieve the total number of records in the Titles table of the Pubs database. Since the total number of records is a single scalar value, the Execute Scalar method is used. The following is the code and its explanation :
 
private void frmSqlCommand_Load(object sender, EventArgs e)
{
    //Sample 03: Open Database Connection
    String con_string = Properties.Settings.Default.ConStrPubs;
    pubs_db_connection = new SqlConnection(con_string);
    pubs_db_connection.Open();
    //Sample 04: Form the Command Object
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "Select Count(*) as Count from Titles";
    cmd.Connection = pubs_db_connection;
    //Sample 05: Execute the Command & retrive scalar value
    lblTotal.Text = System.Convert.ToString(cmd.ExecuteScalar());
}
It is used in disconnected architecture. It represent records in the form of Database table (Row and Column) format. It stores record of one or more tables.
SqlDataAdapter da;
DataSet ds;
string strconn = "Data Source=YourServerName;Initial Catalog=EMP;Integrated Security=True";
private void Form1_Load(object sender, EventArgs e)
{
    da = new SqlDataAdapter("select * from userdet", strconn);
    ds = new System.Data.DataSet();
    da.Fill(ds);
    dataGridView1.DataSource = ds.Tables[0];
}
Methods of DataSet : 
 
AcceptChanges() : This method saves changes which are made with records in a DataSet.
 
Clear() : This method clears (removes) all rows from DataSet.
 
Clone() : The clone method copy the structure of DataSet. Means it copy only schema not full records of DataSet.
 
Copy() : It copies the whole records with structure of DataSet.
 
RejectChanges() : This method discard changes which is made with DataSet and set the DataSet to previous stage (which was at first).
 
HasChanges() : This method return boolean value to show whether record of DataSet has changed or not. It returns true if any changes has made and false if no other changes made.
 
GetChanges() : This method keep copy of those record, which is changed or modified.
Various namespaces available under ADO.NET is given below:
 
System.Data : It contains the definition for rows, columns, relations, views, tables, constraints, and databases.

System.Data.SqlClient : It is a collection of classes that are helpful in connecting to a Microsoft SQL Server database such as SqlConnection, SqlCommand, SqlDataAdapter, etc.

System.Data.Odbc: It consists of classes that are required for connecting with most Odbc Drivers. These classes include OdbcConnection, OdbcCommand.

System.Data.OracleClient : It has classes required for connection with an Oracle database, OracleConnection, OracleCommand.
Different execute() methods supported by SqlCommandObject in ADO.NET is given below :
 
ExecuteScalar() : This method returns only a single value from the first row and first column of the ResultSet after the execution of the query. Even if ResultSet is having more than one row or column, all those rows and columns will be ignored. If the ResultSet is empty, it will return NULL.

ExecuteNonQuery() : This method returns the number of rows affected by the execution of a query. This method is not useful to return the ResultSet.

ExecuteReader() : This method returns an object of DataReader which is a read-only and forward-only ResultSet. It needs a live connection with the Data Source. We cannot directly instantiate the DataReader object. A valid DataReader object can be created with the help of the ExecuteReader() method.

ExecuteXmlReader() : This method builds an object of the XmlReader class and will return the ResultSet in the form of an XML document. This method is made available in SQL Server 2000 or later.
The ExecuteNonQuery method is used to execute the command and return the number of rows affected.
 
The ExecuteNonQuery method cannot be used to return the result set.
 
Snippets working with ExecuteNonQuery
public void CallExecuteNonQuery()
{
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
    try
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "DELETE FROM EMP WHERE DEPTNO = 40";
        cmd.CommandType = CommandType.Text;
        conn.Open();
        Int32 RowsAffected = cmd.ExecuteNonQuery();
        MessageBox.Show(RowsAffected + " rows affected", "Message");
        cmd.Dispose();
        conn.Dispose();
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
The DataRelation is a class of disconnected architecture in the .NET framework. It is found in the System.Data namespace. It represents a relationship between database tables and correlates tables on the basis of matching column.
DataRelation drel;
drel = new DataRelation("All", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0]);
OLEDB provider is used to access any database and provides flexibility of changing the database at any time. SQLClient provider is used to access only SQL Server database but it provides excellent performance than OLEDB provider while connecting with SQL Server database.
There are different methods under SqlCommand and they are :
 
Cancel – Cancel the query

CreateParameter – returns SQL Parameter

ExecuteNonQuery – Executes and returns number of rows affected

ExecuteReader – executes and returns data in DataReader

ExecuteScalar – Executes and returns single value

ExecuteXmlReader – Executes and return data in XMLDataReader object

ResetCommandTimeout – Reset Timeout property
Dataset.clone object copies structure of the dataset including schemas, relations and constraints. This will not copy data in the table.
 
Dataset.copy : Copies both structure and data from the table.
Command is used to execute all kind of queries like DML and DDL. DML is nothing but Insert, Update and Delete. DDL are like Create and drop tables.
 
Command Builder object is used to build and execute DDL queries like Create and Drop Tables.
Following are three different layers of ADO.NET :
 
* Presentation Layer
* Business Logic Layer
* Database Access Layer
Stored Procedure is used for the following reasons :
 
* To improve performance
* Easy to use and maintain
* For security
* Less time taking for execution
* Less Network Traffic
Data Grid :
 
* Data grid has advanced features and facilitates you to do many things like paging and to sort your data without much effort.
* Data grid can hold text data, but not linked or embedded objects.

Data Repeater :
 
* A data repeater doesn't have the paging feature, but it can be done by coding.
* A data repeater can hold other controls and can embed objects.
* A data repeater can embed a data grid within it but vice versa not possible.
Most important features of ADO.NET 2.0:
 
Bulk Copy Operation : It facilitates bulk copy operation from one Data Source to another Data Source.

Batch Update : To update n no of rows in a database table in a single call from a program thus by avoiding round trip to the database.

Data Paging : To read data from a certain index

Connection Details : To get detailed info about connections like buffer information, cursor details, etc.

DataSet.RemotingFormat Property : To make the dataset serialized in Binary

DataTable's Load and Save Methods : For XML interactions.
OLEDB ODBC
An API (Application Programming Interface) enables standard data access from many sources. It's a database management system interface (DataBase Management System).
Both relational and non-relational databases can be used with it. It only works with databases that are relational.
It follows a set of steps. It's built on the concept of components.
It's a lot more straightforward to use. It's a challenge to put into action.
It improves the loading and extraction of data performance. In terms of data loading and extraction, it performs worse than OLE DB.
To connect to an OLE DB data source, use OleDbConnection = New OleDbConnection(connectionString). To connect to an ODBC data source, use the resource ODBC connect(string data source, string username, string password, [int cursor type]). If this method succeeds, it will return a connection resource handle that may be used to access the database with the following instructions.
ADO.NET supports the following two types of transactions
 
Local transaction :
* A local transaction is a one-phase transaction that the database handles directly. For bringing out local transactions, every.NET Framework data provider has its own Transaction object.

* Importing a System, for example, allows us to make a transaction with a SQL Server database. System.Data.SqlClient Import the System if you want to run an Oracle transaction. System.Data.OracleClient For writing code that is not dependent on the provider and requires transactions, a DbTransaction class will be utilized.


Distributed transaction :
* A transaction monitor will coordinate a distributed transaction, which will use fail-safe procedures like a two-phase commit to resolve the transaction. Multiple resources will be impacted by this transaction.

* If a user may utilize a distributed transaction to perform a transaction across many data servers (Oracle, SQL Server, etc. ),

* If a distributed transaction is to commit, all parties must agree that any data changes made are permanent. Even if the system crashes or other unforeseeable circumstances occur, the changes must be preserved. Even if a single participant fails to fulfil this assurance, the transaction as a whole will fail, and all alterations to data within the transaction scope will be rolled back.
ADO.NET is built on an Object Model, which allows data from a database to be accessed through a data provider. It's a data access technique provided by the Microsoft.Net Framework that allows relational and non-relational systems to communicate using a standard set of components.
The following are the elements of the ADO.NET architecture :
 
Data Provider : This component supplies data to any apps that update the database. The DataSet or DataReader object can be used to access data in the application. A data provider is a collection of objects that includes Command, Connection, DataReader, and DataAdapter. Regardless of the operation, such as Insert, Delete, Select, or Update, Command and Connection objects are required.

Connection : The connection object is required to connect to a database such as SQL Server, MySQL, Oracle, and others. To construct a connection object, you'll need to know the database's location (for example, IP address or machine name) as well as the security credentials (Ex: username and password-based authentication or windows authentication).

Command : The component where the SQL queries will be written is the action object. Using the command object, run the queries over the link. Using the action object and SQL queries, you will be able to fetch data or send data to the database.

DataReader :  DataReader is a forward-only connected read-only RecordSet that can be used to read records.

DataAdapter : Between the dataset and the command object, DataAdapter serves as a link. It takes the command object's data and stores it in the data set.

DataSet : A DataSet is a standalone RecordSet that can be explored in both directions. We can also use the dataset to update the data. DataAdapter is used to populate DataSet.

DataView class : A DataView class allows you to generate numerous data views from a DataTable that may be utilized in data-binding applications. You can use this to display the table in a different sorting order, or to filter the data using a filter expression or by row state, for example.

XML : An XML representation of a dataset can be generated. Data is expressed in XML format in the dataset's XML representation, while the database schema is represented in the XML Schema Definition(XSD) language.
Connected Architecture :
* The connection must be kept open in linked architecture in order to access the data retrieved from the database. Connection, DataReader, Command, and Transaction are the classes that make up the Connected architecture.

* You go to the database on a regular basis to perform any CRUD (Create, Read, Update, and Delete) operations. This causes a lot of traffic to the database, but it's usually faster because you're only conducting tiny operations.

* DataReader is a Connected Architecture because it keeps the connection open until all of the rows have been fetched one by one.

Disconnected Architecture :
* Even if the database connection is closed in a disconnected architecture, data retrieved from the database can be accessed. Connection, CommandBuilder, DataAdapter, DataSet, and DataView are the classes that make up the disconnected architecture.

* We obtain and save a record set from the database so that you may execute numerous CRUD (Create, Read, Update, and Delete) actions on the data without having to reconnect to the database.

* Because all records are brought at once and the database connection is not kept alive, DataSet is a Disconnected Architecture.
The SqlTransaction class is an important class of .NET Framework. It ensures that a body of code will affect a Database or kept the same as previous (Rollback).
 
At first we should know about it's two most important method which will be used here. They are given below.
 
Commit() : It commits the transaction. It save changes made in Database during transaction. In simple term we can also say that it shows the end of transaction at that time.
 
Rollback() : It is used to rollback the transaction. It set the database in previous stage which was, before the begin of transaction.
The execute reader method is flexible when we need the result set in the form of an XML doucment. The ExecuteXmlReader methods returns an instance of XmlReader class.
 
Example :
XmlReader xmlreader = cmd.ExecuteXmlReader();
XmlDocument xdoc = new XmlDocument();
Using the XmlDocument class we load the XmlReader object and save it to the File System using the Save method.
A single value from the first row and first column of the ResultSet will be returned by ExecuteScalar() method on query execution.

If the ResultSet is having multiple rows or columns, all those rows and columns will be ignored except the first row and first column. If the ResultSet is empty, this function will return NULL.

The best situation to use ExecuteScalar() method is when we are using functions such as COUNT(), SUM(), etc., as it uses only a few resources compared to the ExecuteReader() method.

Example : 
public void ExecuteScalarExample()  
{  
    SqlConnection con = new SqlConnection();  
    con.ConnectionString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;  
    try  
    {  
        SqlCommand cd = new SqlCommand();  
        cd.Connection = con;  
        cd.CommandText = "SELECT SUM(SALARY) FROM EMPLOYEE";  
        cd.CommandType = CommandType.Text;  
        con.Open();  
        Int32 SalaryTotal = Convert.ToInt32(cd.ExecuteScalar());  
        MessageBox.Show("Total Salary of the employee is : " + SalaryTotal.ToString());  
        cd.Dispose();  
        con.Dispose();  
    }  
    catch (Exception ex)  
    {  
        MessageBox.Show(ex.Message);  
    }  
}​
Here, we create an object of the class SqlConnection and SqlCommand. We pass SQL Statement to the object of SqlCommand class, which returns a single value. When ExecuteScalar() function gets executed, a single value will be returned, i.e, the total salary of employees. This value will be displayed using a message box.
There are seven main objects in ADO.NET. They are:
 
DataSet : It is available under both System.Data.ADO and the System.Data.SQL namespaces. DataSet is a database cache built-in memory for using it in disconnected operations. It holds the complete collection of tables, constraints, and relationships.

SQLDataSetCommand : It represents a stored procedure or a database query that can be used to populate the DataSet object. It corresponds to the ADO’s Command object-provided functionalities.

SQLCommand : It represents a stored procedure or a T-SQL statement that will be executed by SQL Server. It corresponds to another set of functionalities provided by the ADO’s Command object.

SQLParameter : It can be used to pass parameters to the object of SQLCommand or SQLDataSetCommand class. When you are passing a parameter for SQLCommand using SQLParameter, SQLParameter will represent a parameter that can be used by T-SQL statement or stored procedure. Whenever a parameter has been passed for SQLDataSetCommand using SQLParameter, SQLParameter will represent a column from a result set.

SQLConnection : It represents an open connection to the data source like SQL Server. This object is similar to the standard Connection object in ADO.

SQLDataReader : It reads a forward-only stream of data from a SQL Server database. It works with an open database connection.

SQLError : It collects runtime warnings and error conditions related information that will be encountered by an ADO.NET application. It corresponds to ADO’s Error object.
Before performing any task in the database, SQL Server will authenticate. Two types of authentication techniques are:
 
Windows Authentication : This default authentication is provided only through Windows domain accounts. This SQL Server security model is strongly integrated with Windows, so it is also referred to as integrated security. Particular Windows users and group accounts are allowed to login into SQL Server. Windows users who are already been authenticated or logged onto Windows do not have to provide additional credentials.

The below-given SqlConnection.ConnectionString specifies Windows authentication without any need of providing a user name or password by the user.
"Server=MSSQL1;Database=Institute;Integrated Security=true;​
SQL Server and Windows Authentication Mode(Mixed-mode) : Authentication will be provided with the help of the Windows and SQL Server Authentication combination. User name and password pair will be maintained within SQL Server. In order to use this mixed-mode authentication, you need to create SQL Server logins that are stored in SQL Server. After that, you can supply the user name and password to SQL Server at run time.

The below-given ConnectionString specifies Mixed mode authentication:
"Persist Security Info=False;User ID=Harsh;Password=xyz@123;Initial Catalog=Institute;Server=MySqlServer"
* Response.Expires property is specific to the minutes that a particular page stays in the cache for the specific time from the time it has been requested. For example, if Response.Expires value is set to 5 minutes, then the page is instructed to be in cache for 5 minutes from the time it has been requested.

* Response.ExpiresAbsolute property helps to provide the proper time at which a specific page cache has been expired. For example, Response.ExpiresAbsolute provides information like 14 March 15:40:15. This time tells about when the page was in cache.
The DataSet object has two methods to track down the changes :
 
GetChanges() : It returns the DataSet object that has been changed since it was loaded or since the execution of the AcceptChanges() method.

HasChanges() : It indicates if any modifications were made since from the time the DataSet object was loaded or after a method call to the AcceptChanges() was made.

Use the RejectChanges() method, if you want to reverse the entire changes since from the time the DataSet object was loaded.
Serialization is the method of converting an object into a byte stream which can be stored as well as transmitted over the network. The advantage of serialization is that data can be transmitted in a cross-platform environment across the network and also it can be saved in a storage medium like persistent or non-persistent.
 
The code for serializing a DataSet is :
using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml.Serialization;
using System.IO;
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("Data Source=data_source_name;Initial Catalog=employee;Integrated Security=True");  //Create connection object
        SqlDataAdapter da = new SqlDataAdapter("select * from emp", conn);  //DataAdapter creation
        DataSet s = new DataSet();
        da.Fill(s);  
        FileStream fObj = new FileStream("C:\\demo.xml", FileMode.Create);   // Create a XML file
        XmlSerializer sObj = new XmlSerializer(typeof(DataSet));
        sObj.Serialize(fObj, s);  //Serialization of a DataSet
        fObj.Close();
    }
}
In the above given example, the database name is employee and, the table name is emp. The data in a DataSet will be serialized and stored in a demo.xml file by using Serialize() method.
The BindingSource class is used to simplify data binding as well as various operations on records. It has different methods like AddNew( ), MoveFirst( ), MovePrevious( ), MoveNext( ), etc which provide easier way for adding new row, moving to first record, moving to previous record, moving to next record and many other operations without writing code for them.