All You Need to Know about ADO.NET: Part 2/2
page 4 of 27
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 91523/ 215

The DataReader Object

Sometimes an application is only required to read data and not to update or write the data. Especially if such applications need large amount of data, then it is wiser to do away with the DataSet object because of its memory overheads. The DataReader requires very little memory because it just reads the data as its name suggests. It reads only one record at a time, and for applications using huge read only data, the DataReader is an excellent alternative because it is a read only and forward only stream that cuts down significantly on memory requirements.

After creating an instance of the Command object, a DataReader can be created by calling Command.ExecuteReader to retrieve rows from a data source. Assuming a connection as in the previous example is set up, the following code illustrates how to loop through a DataReader:

Dim dReader As OleDbDataReader
Set dReader = Nothing
dReader = cmd.ExecuteReader(
Do While dReader.Read
End While

The code above loops through the publishers table in the pubs database and displays the pub_id value for all of the publishers.

The Read method of the DataReader object is used to obtain a row from the results of the query. Columns can be accessed by passing the name or ordinal reference of the column to the DataReader. However, for best performance, the DataReader provides a series of methods that allow you to access column values in their native data types (GetDateTime, GetDouble, GetGuid, GetInt32, and so on).

View Entire Article

User Comments

Title: disconnected architecture   
Name: kinjalpadashala
Date: 2012-02-14 3:19:39 AM
p/z help me how to select the data in grid and bind of textbox.
Title: thank you   
Name: kartik
Date: 2011-03-24 1:04:35 AM
is it posibile to insert the record enter at the 1st row of database every time?
Title: Connected Architecture   
Name: Vidhya Patel, India(mota)
Date: 2011-03-08 11:27:53 PM
I use this content in my's very useful for me....... so thanks a lot
Name: Manimegalai
Date: 2010-09-15 3:31:43 AM
That is great collection
thank u;;;;;;;;;;;;;;
Title: Thanks   
Name: Amin Anwar
Date: 2009-05-14 5:19:09 AM
That isgr8 collection;;;
Name: Saurabh Shrivastava
Date: 2007-02-20 11:46:46 AM
Brilliant Work,It could be more useful by giving some code in it.
Title: Thank you   
Name: Jayalakshmi baskaran
Date: 2006-05-30 5:39:23 AM
I want to create the sqldataAdapter and the Dataset in Code
Can you please help it out
Title: Ado.Net   
Name: Rohan Ragoo
Date: 2006-01-09 12:37:59 PM
Excellent Overview. All topics are dicussed in an effective timeline.
Title: XML   
Name: Rajesh Medackel,India
Date: 2005-10-01 5:26:30 AM
Good write up .... Thanx
Title: ADO.Net   
Name: k
Date: 2005-05-03 11:31:30 AM
to the authors thanks a lot for the unselfish information

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2023  |  Page Processed at 2023-10-04 1:44:08 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search