ASP.NET
  Home arrow ASP.NET arrow Page 3 - Adding Methods to the StudentDataAccess Cl...
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 
Moblin 
JMSL Numerical Library 
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

Adding Methods to 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 / 2
    2007-09-18

    Table of Contents:
  • Adding Methods to the StudentDataAccess Class for ASP.NET 2.0
  • The InsertNewStudent() and UpdateStudent() methods
  • Testing the methods from a Web page
  • Creating the DeleteStudent() method
  • The StudentDataAccess class, the complete code

  • 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


    Adding Methods to the StudentDataAccess Class for ASP.NET 2.0 - Testing the methods from a Web page


    (Page 3 of 5 )

    Write the following code inside the Page_Load() event handler method of the page Default.aspx:

    StudentDataAccess newStudent = new StudentDataAccess();
    newStudent.FirstName = "Jackson";
    newStudent.LastName = "Robin";
    newStudent.Major = "Information Systems";
    newStudent.DateOfBirth = DateTime.Parse("11/5/1982");
    newStudent.AdmissionDate = DateTime.Now;
    newStudent.Active = true;
    newStudent.SaveStudent();

    int newStudentId = newStudent.StudentId;
    StudentDataAccess student = new StudentDataAccess(newStudentId);

    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 />");

    newStudent.Major = "Computer Science";
    newStudent.Active = false;
    newStudent.SaveStudent();

    student = new StudentDataAccess(newStudentId);

    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 />");

    Now run the page and you will get the result shown below.

    We created a StudentDataAccess object and assigned values to its properties. Then we called the SaveStudent() method, and because this is a new student those values are inserted into the Students table, by calling the private InsertNewStudent() method. After that we store the StudentId in a local variable and pass it to the StudentDataAccess constructor to create a populated object from that StudentId, as we have seen before. We then use the Response.Write() method to print out the values of the properties of that new object.

    Next we update the Major and the Active properties of the the newStudent object, and call its SaveStudent() method. Because the newStudent.StudentId property's value has a valid studentId value, this call to the SaveStudent() method will update the record by calling the private UpdateStudent() method. Again we check the updates through creating another StudentDataAccess object with that studentId value and print out its values.

    More ASP.NET Articles
    More By Michael Youssef


       · Ok by now we have a complete data access class. It's also good to read the 3...
     

    ASP.NET ARTICLES

    - 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
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...





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