ADO.NET
  Home arrow ADO.NET arrow Page 4 - A Practical Comparison of ADO and ADO.NET
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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? 
ADO.NET

A Practical Comparison of ADO and ADO.NET
By: Joe O'Donnell
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 45
    2002-03-01

    Table of Contents:
  • A Practical Comparison of ADO and ADO.NET
  • Old versus new: ADO versus ASP.NET
  • Connecting to a database
  • Working with recordsets/rowsets
  • Calling stored procedures
  • Retrieving records as XML
  • Conclusion

  • 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

    Anyone looking for a way to modernize legacy data or easily migrate to a more cost-effective database without sacrificing functionality will benefit from this seminar. View the Intro to Advantage Database Server now!

    A Practical Comparison of ADO and ADO.NET - Working with recordsets/rowsets
    (Page 4 of 7 )

    [Note] In ADO 2.x, we used the term recordset to refer to a collection of records returned from a query. In ADO.NET we use the term rowset. [End Note]

    If we wanted to use a recordset object in ADO 2.x to store the results of a query and loop through these results, we could do so by calling its open and movenext methods. We could also check whether there were any records beyond our cursor by checking its eof variable, like this:

    objRS.ActiveConnection = objConn

    objRS.LockType = 1 'adLockReadOnly

    objRS.CursorType = 0 'adOpenForwardOnly

    objRS.Open "SELECT au_fname + ' ' + au_lname as name FROM authors"

    while not objRS.EOF

    Response.Write objRS("name") & "<br>"

    objRS.MoveNext

    wend


    In ADO.NET, the OleDbDataReader and SqlDataReader classes can be used to hold rowsets. Both of these classes cannot be directly instantiated, and can only be created as a result of a call to the ExecuteReader method, like this:

    string strQuery = "SELECT au_fname + ' ' + au_lname as name FROM authors";

    SqlCommand objCmd = new SqlCommand(strQuery, objConn);

    objCmd.CommandType = CommandType.Text;

    SqlDataReader objDR = objCmd.ExecuteReader();

    while(objDR.Read())

    {

    Response.Write(objDR["name"] + "<br>");

    }


    The Read() method of the SqlDataReader in our example above advances the rowsets cursor and gives us access to the next row. The SqlDataReader class has an overloaded indexer to accept either the name or index of the field to return. We could just as easily specify a field index rather that a name, like this:

    while(objDR.Read())

    {

    Response.Write(objDR[0] + "<br>");

    }


    The return type from the SqlDataReaders indexer is actually an object, which, in our example above is implicitly converted to a string. If we knew that a field was going to be a specific data type, then we could specify an explicit case using C style casting:

    while(objDR.Read())

    {

    // Perform an explicit case from object to int32

    int intAge = (int)objDR[5];

    }


    [Note] When using both the OleDbDataReader and SqlDataReader classes, field indexes start at 0 and not 1. [End Note]

    More ADO.NET Articles
    More By Joe O'Donnell


     

    ADO.NET ARTICLES

    - Datasets in Microsoft.Net
    - Latest Developments in the .Net World
    - Introduction to .NET
    - Automatic Generation of Single Table SQL Sta...
    - Data Access in .NET using C#: Part 1
    - All You Need To Know About ADO.NET: Part 2/2
    - All You Need To Know About ADO.NET: Part 1/2
    - Easing Transition From ASP and ADO to ASP.NE...
    - A Practical Comparison of ADO and ADO.NET


     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     





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