ADO.NET
  Home arrow ADO.NET arrow Page 6 - 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  
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

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 / 46
    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
     
     
    ADVERTISEMENT


    A Practical Comparison of ADO and ADO.NET - Retrieving records as XML


    (Page 6 of 7 )

    SQL Server supports retrieving data using the FOR XML AUTO, FOR XML RAW, or FOR XML EXPLICIT keywords. Using ADO 2.6, we typically setup our query/stored procedure by adding FOR XML AUTO at the end of it and created a new ADO stream object, like this:

    objComm.ActiveConnection = objConn

    objComm.CommandType = 1 'adCmdText

    objComm.CommandText = "SELECT TOP 1 * FROM authors FOR XML AUTO"

    objComm.Properties("Output Stream") = objStream

    objStream.Open

    objComm.Execute , , 1024 'adExecuteStream

    Response.Write objStream.ReadText


    The output from the ASP/ADO code above return one record in the form of XML, which looks like this:

    <authors au_id="172-32-1176" au_lname="Whitles" au_fname="Johnson" phone="408 496-7223" address="10932 Bigge Rd." city="Menlo Park" state="CA" zip="94025" contract="1"/>

    ADO.NET makes it easier to work with XML, and provides a class call XmlReader, which exists in the System.Xml namespace. The ExecuteXmlReader() function returns an instance of the XmlReader class. We can loop through the results of that XmlReader class using its ReadOuterXml() function, like this:

    <%@ import namespace="System.Data" %>

    <%@ import namespace="System.Xml" %>

    <%@ import namespace="System.Data.SqlClient" %>

    <script language="c#" runat="server">

    public void Page_Load(object sender, EventArgs e)

    {

    SqlConnection objConn = new SqlConnection("Server=(local); Database=Pubs; UId=sa; Pwd=");

    objConn.Open();

    SqlCommand objComm = new SqlCommand("SELECT TOP 1 * FROM authors FOR XML AUTO", objConn);

    objComm.CommandType = CommandType.Text;

    XmlReader objXR = objComm.ExecuteXmlReader();

    while(objXR.Read())

    {

    Response.Write(objXR.ReadOuterXml());

    }

    }

    </script>


    The above script does exactly the same thing as the ADO/ASP example shown earlier, displaying an XML element in the browser.

    More ADO.NET Articles
    More By Joe O'Donnell


       · Great article as it helps the transition. Unfortunately it is heavily .net...
     

    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 4 Hosted by Hostway
    Stay green...Green IT