Tuesday, April 17, 2012

How to use DataReadear in asp.net

Title: What is Data Reader and How to use Data reader

Description:Data reader is Read only and forward only.Simple description for those two properties
Read Only-->Data Reader doesn't support manipulation[insert,delete]
Forward Only-->Data Reader supports Reading records is forwarding direction[Reading only once]

VB.Net:
Dim cms As New OleDbCommand("select*from dept",cn)
Dim dr As OleDBDataReader
dr=cms.ExcuteReader()

C# Syntax:
Before going to use the data reader we should add the name System.Data.SqlClient to our application
SqlDataReader reader =new SqlDataReader();
dr.Read():-It will fetch a record into application process.It returns True fetching record is successfully else false
dr.Item(ColIndex/ColName) or dr(ColIndex/ColName) :-This can be used for any type of data
dr.GetData():-It will produce  better performance
dr.FieldCount:-It returns column count
dr.HasRows:-True:Records are available
                     False:Records are not available
dr.Close:-It will Release memory
dr is a pointer to the temp memory.where the records stored.
Data Reader will fetch record by record and it will consume only one record memory with in  application process.This will reduce burden on application process.Data Reader is strongly recommend when the application requirement is reading data only once with out manipulation

No comments:

Bel