Database
  Home arrow Database arrow Page 2 - ADO.NET 101: SqlDataReader
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

ADO.NET 101: SqlDataReader
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2005-03-15

    Table of Contents:
  • ADO.NET 101: SqlDataReader
  • SQLDataReader Class
  • SQLCommand Execution
  • SQLCommand for CommandType: SQL Statement
  • SQLCommand for CommandType: Stored Procedure
  • Stored Procedure with one input and one output parameter
  • SQLCommand's ExecuteXMLReader() Method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    ADO.NET 101: SqlDataReader - SQLDataReader Class


    (Page 2 of 7 )

    The SQLDataReader object (as well as the other analogous ODBCDataReader, OleDbDataReader and OracleDataReader objects) does not have a GUI, but is accessed via SQLCommand. SqlDataReader is used to retrieve read-only, forward-only, row after row of streaming data from the SQL Server. Since the DataReader is connected to the server, it should be closed after retrieving the necessary data. While the data is streaming into the SQLDataReader, the connection is busy and cannot be used for other purposes. DataReader is especially useful if fast access is needed. As it retrieves, there will be only one row in the memory, reducing system ovehead.

    SQLDataReader is a non-inheritable class, and this next screen shot shows the Class Viewer showing the details of the SQLDataReader class. It has a few properties and a large number of methods as shown in this class view. For best performance use the various Get.... methods of DataReader. If the column datatype is known before hand, using these typed accessor methods will improve performance because no data conversion is involved in retrieval. As will be seen presently, column or field access can be both by name and ordinal reference.

    ADO.NET 101: SqlDataReader

    The properties of the SQLDataReader can be utilized to find the number of columns of data retrieved, whether or not any rows are returned by a command, and whether the reader is closed, or open, as shown in this tutorial. Very simply stated, in order to work with SQLDataReader, follow this recipe:

    • Establish a SqlConnection and open the connection

    • Create a SQLCommand

    • Use one of the execute methods of the SqlCommand to enable the reader

    • Optionally monitor SQLDataReader's Properties

    • Read the contents of the SQLDataReader

    • Close the SqlDataReader

    • Close the SqlConnection

    More Database Articles
    More By Jayaram Krishnaswamy


     

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT