Home  »  Articles  »  ADO.Net  »

What is DataSet and DataReader in .Net?

 Posted By : Manoranjan SahooPosted Date : 24/11/2010 03:04:01 PM Category : ADO.Net Points : 5

DataSet :
Dataset is a disconnected, in-memory representation of data. It is a major component of the ADO.NET architecture. It can contain multiple datatables from different database. It contains multiple Datatable objects, which contain columns and rows, just like normal data base tables. You can even define relations between tables to create parent-child relationships
with DataRelation objects. You can also enforce data integrity in the DataSet by using the UniqueConstraint and ForeignKeyConstraint objects. For further details see below links :

http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx

Data Reader :

Data reader is an object of ado.net .Data reader is use to fetch the record from data base .The execution of data reader is fast . But it provides a forward-only, read-only, connected recordset. It is most efficient to use when data need not to be updated, and requires forward only traverse. In other words, it is the fastest method to read data.
Advantage-> The main Advantage of datareader is fast execution .
Disadvantage-> In disadvantage we can say it does't work in disconnected mode therefore intresting thing is that we can't use data reader for paging.

Example:

   1. Filling dropdownlistbox.
   2. Comparing username and password in database.
   3. generating reports from database

SqlCommand cmd=new SqlCommand();
cmd.CommandText = strSqlQuery;
cmd.CommandTimeout = 0;
cmd.Connection = sqlconn;
SqlDataReader dr = cmd.ExecuteReader();
//Reading data
while (dr.Read())
{
     //Display data
  string name = dr["Name"].ToString();
  string address = dr["Address"].ToString();
  string city = dr["City"].ToString();
}

Responses
No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.