DataReader :-



  1. DataReader will work with connection oriented Architecture Second Method .
  2. DataReader is Read-only object i.e., using DataReader we can just read the data from the database, and we cannot perform any operations like Inserting, Updating and deleting records etc.
  3. DataReader is sequential only object i.e., can read the records one by one only.
  4. There is no mechanism to move Nth  record Directly.
  5. DataReader is Forward object i.e., it is possible to read current record to next record only. and it is not possible to read the previous record from current record.
  6. DataReader will use the command object to fetch the data from database.
  7. Data reader will reserve the connection object i.e., as long as we are working with DataReader connection object cannot be used for other purpose.

Architecture of DataReader:-



S1:-Establishing the connection to the Server.
S2:-client sends the request to the server using Command Object for the Required Data
.
S3:-Client request is processed at the server and Query Execution Result is transferred to the separate Memory allocated to the client at server known as ResultSet.
S4:-Link is created from the header row of ResultSet DataReader
S5:- DataReader starts read the data using Read() Method.
S6:-The data ready by using DataReader can be Displayed in the user Interface Elements/used for calculation purpose/for any other purpose.
After completion of the total reading the data either DataReader can be closed or Connection is Closed.
When ResultSet is Destroyed
  1. When DataReader is Closed
  2. When Connection is Closed

Identify the Data Using DataReader:-

In the above figure if DataReader is reading the first record then we identify the field data using the index value or field name like.

DR[0]    or   DR[“EmpId”]                 ---        1    

DR[1]    or   DR[“EName”]                ---       Sampath

DR[2]    or   DR[“Doj”]                      ---       10/12/2012

DR[3]    or   DR[“Salary”]                  ---       15000



Properties:-

SNo
Properties & options
Type
Description
 01
FieldCount
Int
Returns the count of fields present in the ResultSet
 02
IsClosed
Bool
Returns true if DataReader is closed otherwise return false


Methods with DataReader Class:-

SNo
Properties & options
Type
Description
 01
Close()
Void
Closes the SQL DataReader object
 02
Read()
Bool
Advaances the DataReader to the Next record
Return true of there is another record otherwise returns false if there is no Recoed.

Advantages:- 

  •   Using the DataReader can increase Application performance both by Retrieve data as soon as it is available, and (By Default) storing only one row at a time in memory, reducing system overhead. 
  •   The DataReader is a good choice when retrieve large amounts of data because the data is not cached in Memory.


No comments:

Post a Comment