ADO.NET
  Home arrow ADO.NET arrow Page 3 - Easing Transition From ASP and ADO to ASP....
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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? 
ADO.NET

Easing Transition From ASP and ADO to ASP.NET and ADO.Net Part 1/2
By: Ruffin Bailey
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2002-03-21

    Table of Contents:
  • Easing Transition From ASP and ADO to ASP.NET and ADO.Net Part 1/2
  • Making the connection
  • Where did my RecordSet go?
  • Creating Column Headers
  • 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
     
     
    ADVERTISEMENT


    Easing Transition From ASP and ADO to ASP.NET and ADO.Net Part 1/2 - Where did my RecordSet go?


    (Page 3 of 5 )

    There's no RecordSet equivalent in ADO.NET. ADO.NET prefers to employ a disconnected data architecture where you fill up miniature copies of your database with data and then work directly with these miniature copies. These copies are stored in DataSets and are filled by DataAdapters. They can contain DataRelations and all sorts of other overhead, as well as new objects whose data models we don't need to deal with to simply display the data.

    What you might not realize is that not all ADO.NET objects use the disconnected data architecture. ADO.NET provides an object that opens a connection to a data source and reads the data over the open connection while you're working with it. This object then needs to be closed to free up the original connection to the database, and all of this is in concert with a data provider (like SQLOLEDB for example). Sounds like a RecordSet object to me, right?

    This object is actually called the DataReader, and it provides us with a subset of what we used to get with ADO's RecordSet object, namely an object with adOpenForwardOnly and adLockReadOnly as our only options. Although the disconnected data architecture with miniature copies of subsets of databases is preferable in many conditions, one thing Microsoft realized is that what we weren't going to want to do is make a copy of our entire database for each user that connects to it and requests to view our data.

    The DataReader object allows us to take all data that matches our command (in this case, an SqlCommand object) and instead of creating the overhead needed to store this data in a "mini-database", we're allowed to step-in and use the data stream directly. This is exactly what we've been doing in classic ASP for years.

    If we want to move forward and backwards through out data and also update the data that the user is currently viewing, then we'll need something more powerful, however forward-only, read-only operations are the DataReader's specialty.

    Let's look at how we can create an SqlDataReader object by using the ExecuteReader method of an SqlCommand object:

    SqlDataReader readPubs = cmdTemp.ExecuteReader();

    That's all there is to it... we've finally found our RecordSet equivalent in ADO.NET!

    [Note] Each of the three pages contained in the support material contain the same code up to one specific point in the file. Whether we hardcode output, dynamically create our own DataGrid replacement, or use the Microsoft DataGrid object, we still create the SqlDataReader the same way. [End Note]

    But I don't wanna use the DataGrid!

    At this point, most tutorials regarding DataReaders will show you how to bind your new DataReader object to a DataGrid and will use the ASP:DataGrid object in HTML code. The DataGrid would insert a fairly plain table into our HTML code. The table produced by this DataGrid would have very little formatting, less than ideal spacing in the dynamically generated HTML code, and would leave you with a whole new object model to learn before you could fully customize the HTML code you're sending to the user.

    Let's take our DataReader object and send it through the same logical steps we would have used in a well-done classic ASP page. I'm going to take the results from the logic in this code and add it to a string object I've created, rather than write it to the browser with the response object piecemeal.

    StrReturn will include the entire HTML markup for the table I'm about to create. In my opinion, this is one step better than pure "spaghetti code", where the HTML is interspersed between <% and %> tags. By doing all our work with one string, we're only one call to Response.Write away from inserting our new object, which makes for cleaner code. It'll also speed our transition to the codebehind method in part two of this article.

    More ADO.NET Articles
    More By Ruffin Bailey


     

    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







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