.NET
  Home arrow .NET arrow An introduction to ADO.NET concluded
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
.NET

An introduction to ADO.NET concluded
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    2006-01-05

    Table of Contents:
  • An introduction to ADO.NET concluded
  • ADO.NET datasets
  • The dataset classes
  • Concurrency and the disconnected data architecture

  • 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


    An introduction to ADO.NET concluded


    (Page 1 of 4 )

    This article, the second of two parts, explains how ADO.NET uses classes from the .NET Framework to provide access to the data in a database. It is excerpted from chapter two of the book VB.NET Database Programming with ADO.NET, written by Anne Prince and Doug Lowe (Murach Publishing; ISBN: 1890774197).

    The SqlDataReader class

    A data reader provides an efficient way of reading the rows in a result set returned by a database query. In fact, when you use a data adapter to retrieve data, the data adapter uses a data reader to read through the rows in the result set and store them in a dataset.

    A data reader is similar to other types of readers you may have encountered in the .NET Framework, such as a TextReader, a StreamReader, or an XMLReader. Like these other readers, a data reader lets you read rows but not modify them. In other words, a data reader is read-only. In addition, it only lets you read rows in a forward direction. Once you read the next row, the previous row is unavailable.

    Figure 2-5 lists the most important properties and methods of the SqlDataReader class. You use the Read method to read the next row of data in the result set. In most cases, you’ll code the Read method in a loop that reads and processes rows until the end of the data reader is reached.

    To access a column of data from the current row of a data reader, you use the Item property. To identify the column, you can use either its index value like this:

      drVendors.Item(0)

    or its name like this:

      drVendors.Item("VendorName")

    Since Item is the default property, you can also omit it like this:

      drVendors("VendorName")

    The SqlDataAdapter class

    As you know, the job of a data adapter is to provide a link between a database and a dataset. The four properties of the SqlDataAdapter class listed in figure 2-5 identify the four SQL commands that the data adapter uses to transfer data from the database to the dataset and vice versa. The SelectCommand property identifies the command object that’s used to retrieve data from the database. And the DeleteCommand, InsertCommand, and UpdateCommand properties identify the commands that are used to update the database based on changes made to the data in the dataset.

    To execute the command identified by the SelectCommand property and place the data that’s retrieved in a dataset, you use the Fill method. Then, the application can work with the data in the dataset without affecting the data in the database. If the application makes changes to the data in the dataset, it can use the data adapter’s Update method to execute the commands identified by the DeleteCommand, InsertCommand, and UpdateCommand properties and post the changes back to the database.

    Figure 2-5.  The SqlDataReader and SqlDataAdapter
                                  classes

    Common properties and methods of the SqlDataReader class

    Common properties and methods of the SqlDataAdapter class

    Description

    • A data reader provides read-only, forward-only access to the data in a database. Because it doesn’t require the overhead of a dataset, it’s more efficient than using a data adapter. However, it can’t be used to update data.
    • When the Fill method of a data adapter is used to retrieve data from a database, the data adapter uses a data reader to load the results into a dataset.

       

    More .NET Articles
    More By Murach Publishing


       · This article is an excerpt from the book "VB.NET Database Programming with ADO.NET,"...
       · how to avoid concurency in dataset by using ds.timestamp
     

    Buy this book now. This article is excerpted from chapter two of the book VB.NET Database: Database Programming with ADO.NET, written by Anne Prince and Doug Lowe (Murach Publishing; ISBN: 1890774197). Check it out today at your favorite bookstore. Buy this book now.

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek