A DataReader is a read-only forward-only way of reading data. It is quiet fast when compared to fetching data using a DataSet.
Some important point:
Read-only access
Supports a single table based on a single SQL query of one database
Connected mode
Bind to a single control
Forward-only scanning of data
Faster access to data
Lightweight object with very little overhead
Must be manually coded
Code Sample:
 SqlConnection myconn = new SqlConnection(connString);
 SqlCommand mycomm = new SqlCommand("select * from emp", myconn);
 mycomm.Connection.Open();
 SqlDataReader dr =  
     mycomm.ExecuteReader(CommandBehavior.CloseConnection);
 while(dr.Read())  
 {
   Console.WriteLined(r.GetString(0));
 }
 dr.Close();
 myconn.Close();
Thanks & Regards
Santosh






0 comments:
Post a Comment