Friday, April 1, 2016

Difference between Data Reader, Data Adapter, Dataset in C #



Data Reader 

Data Reader is used to read the data from Data Base in forward direction only Data Reader read the data in connected environment it will fetch the data very fast as comparison to Data set.

C# code 

Sqlconnection con=new Sqlconnection (“Data Source=.; integrated security=true; initial catalog=Master”)
{
con.open( );
Sqlcommand cmd=new Sqlcommand(“select * from emp”, con);
SqlDataReader dr= cmd.ExecuteReader ();
con.close();
}

Data Adapter

Data Adapter will work as a bridge between Data Reader and Data set, it is worked in disconnected architecture. Data Adapter is used to read the data from database and bind the data from data base.

Data set 

Data set work in the disconnected environment is the collection of Data tables and relations between tables .It is used to hold multiple tables with data. Data set also provides features like saving data as XML and loading XML data.

C# code 

Sqlconnection con=new Sqlconnection (“Data Source=.; integrated security=true; initial catalog=Master”)
{
con.open( );
Sqlcommand cmd=new Sqlcommand(“select * from emp”, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
 DataSet ds = new DataSet();
 da.Fill(ds);
}


No comments:

Post a Comment