ASP.NET
  Home arrow ASP.NET arrow Page 4 - Improving the StudentDataAccess Class for ...
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 
Mobile Linux 
App Generation ROI 
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? 
ASP.NET

Improving the StudentDataAccess Class for ASP.NET 2.0
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-09-17

    Table of Contents:
  • Improving the StudentDataAccess Class for ASP.NET 2.0
  • Creating the StudentData AccessCollection class
  • Creating the GetAllStudents() method
  • Testing the GetAllStudents() method
  • Modifying the application to retrieve all the columns

  • 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


    Improving the StudentDataAccess Class for ASP.NET 2.0 - Testing the GetAllStudents() method


    (Page 4 of 5 )

    Replace the code that you have written in the Page_Load() event handler with the following:

    StudentDataAccessCollection students = StudentDataAccess.GetAllStudents();
    foreach (StudentDataAccess student in students){
      Response.Write("<b>Student ID:<b/> " + student.StudentId +
    "<br />" +
    "<b>Student First Name:<b/> " + student.FirstName + "<br />" +
    "<b>Student Last Name:<b/> " + student.LastName + "<br />" +
    "<b>Student Date Of Birth:<b/> " + student.DateOfBirth + "<br />"
    +
    "<b>Student Admission Date:<b/> " + student.AdmissionDate +
    "<br />" +
    "<b>Student Major:<b/> " + student.Major + "<br />" +
    "<b>Student Active:<b/> " + student.Active + "<br />"
      );
      Response.Write("<br />");
    }

    Run the page and you will get all the records of the Students table.

    We assigned the return object to calling the GetAllStudents() method to an object called students of type StudentDataAccessCollection, then we used a foreach statement to iterate over the StudentDataAccess objects of that students collection and printed out the values of the fields. As you can see, we have accessed each object of the StudentDataAccessCollection in a strongly typed syntax as in student.FirstName and student.LastName.

    Note that to return these StudentDataAccess objects we have communicated with the database many times. The first communication happened when we retrieved the StudentID column's values and the other four communications (because we  have four records in the database) took place when we passed the StudentID column's values to the StudentDataAccess constructor to populate the object's fields from the database. This is fine for our example, but imagine that you are executing this code against a database with thousands of records; it would slow down the application's performance. To solve this problem, move on to the next section to see how we handle this situation.

    More ASP.NET Articles
    More By Michael Youssef


       · Make sure that you read the article "Building the StudentDataAccess Class for...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





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