Database
  Home arrow Database arrow Page 3 - 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 - SQLCommand Execution


    (Page 3 of 7 )

    SQLCommand's Execute Methods

    The SQLCommand, prepared and ready, must be executed against the database.

    However, there are several ways of executing the command,

    • ExecuteReader() method returns forward only, read only, SQLDataReader.

    • ExecuteScalar() retrieves a single value (first row, first column).

    • ExecuteNonQuery() does not return results. For example, a stored procedure may not return values, if it is making changes to database only.

    • ExecuteXMLReader() returns an XML version of the DataReader. The command has to return XML type.

    In this tutorial, only the ExecuteReader() and the ExecuteXMLReader() methods of execution will be considered.

    SQLCommand's ExecuteReader() Method

    SQLCommand Type

    In order to use the SQLDataReader, a SQLCommand is necessary. There are three SQL Command Types as seen below.

    ADO.NET 101: SqlDataReader

    Of these three, the TableDirect type is not supported by the .NET provider for SQL. However this is supported by the OleDB providers. This will be discussed towards the end of this article. The CommandType text is usually an SQL Statement (which also happens to be the default type) and the type Stored Procedure is for a named Stored Procedure on the SQL server.

    Visual Studio's Data Controls from the ToolBox can be dragged and dropped on the Design Pane and can be configured in-situ. This will be dealt with in another article. In this article, mostly code based data access procedures will be discussed. However, for rapid prototyping, and to understand the syntax without resorting to heavy reading (online or off line), the GUI-based approach is invaluable.

    • CommandType:SQL Statement
    • CommandType:Stored Procedure
      • Simple Stored procedure:no parameters
      • Stored Procedure with input parameter
      • Stored Procedure with input & output parameters

    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 2 hosted by Hostway
    Stay green...Green IT