SunQuest
 
       .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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
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? 
.NET

An introduction to ADO.NET concluded
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 12
    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
     
    Iron Speed
     
    ADVERTISEMENT

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    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

    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...
    - Coding an AjaxPro.NET Based Search Engine fo...
    - Building an AjaxPro.NET Based Search Engine ...




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