ASP.NET
  Home arrow ASP.NET arrow Page 3 - Creating a StudentDB Class for ASP.NET 2.0
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

Creating a StudentDB Class for ASP.NET 2.0
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2007-09-05

    Table of Contents:
  • Creating a StudentDB Class for ASP.NET 2.0
  • Creating the Website and the App_Code Folder
  • Writing the Student class
  • Storing the Connection String in a Web.Config file
  • The StudentDB class

  • 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


    Creating a StudentDB Class for ASP.NET 2.0 - Writing the Student class


    (Page 3 of 5 )

    As we have said before, the Student class represents a record of the Students database table. That means we need to simulate the table's fields with C# properties for that class. So we are going to create seven properties to represent the record. Please wait until we write the data access code and I'm sure that you will fully understand this technique, but for now let's see the code for the Student class. The following is the code you need to copy and paste, or write it by hand if you wish, in place of the auto-generated code of the Student.cs file:

    using System;

    public class Student
    {
      private int studentId;

      public int StudentId
      {
        get { return studentId; }
      }
      private string firstName;

      public string FirstName
      {
        get { return firstName; }
        set { firstName = value; }
      }
      private string lastName;

      public string LastName
      {
        get { return lastName; }
        set { lastName = value; }
      }
      private DateTime dateOfBirth;

      public DateTime DateOfBirth
      {
         get { return dateOfBirth; }
         set { dateOfBirth = value; }
      }
      private DateTime admissionDate;

      public DateTime AdmissionDate
      {
        get { return admissionDate; }
        set { admissionDate = value; }
      }
        private string major;

      public string Major
      {
        get { return major; }
        set { major = value; }
      }
      private bool active;

      public bool Active
      {
        get { return active; }
        set { active = value; }
      }

      public Student(int studentId, string firstName, string lastName, DateTime dateOfBirth, DateTime admissionDate, string major, bool active)
      {
        this.studentId = studentId;
        this.firstName = firstName;
        this.lastName = lastName;
        this.dateOfBirth = dateOfBirth;
        this.admissionDate = admissionDate;
        this.major = major;
        this.active = active;
      }
    }

    As you can see, there is nothing complicated about this class, but note the difference between the data types used here and the data types we used when we created the Students table on SQL Server, like NVARCHAR, INT, DATETIME and BIT. We will talk more about that in the next part of the series, but for now let's continue. 

    We have also added a constructor to the class that accepts values for all the private instance variables as parameters. You will see how this constructor is useful soon. Now let's do one more thing. Before we move on to creating the StudentDB class, we need to create the connection string that will be used by the static methods of the StudentDB class to access the database. Let's do that now. 

    More ASP.NET Articles
    More By Michael Youssef


       · i haven't developed any real projects before because i still learning C# and asp.net...
       · Hi, Of course, you can read the article. It's not that difficult if you have...
       · A very good explanation, I visited ASP.net for first time and i find the very first...
       · Thanks, the next 2 article will be interesting more than this one. You will...
       · Very good article and can't wait for the second and third parts. are you going to...
       · Very good article and can't wait for the second and third parts. are you going to...
       · You will like the following articles even more.About the SqlDataSource control, I...
       · Nice article Michael but I need the other articles to complete the class. when we...
       · You will be reading the articles in the next few weeks. Tell me what do you think...
       · If you have an idea about an article related to ASP.NET 2.0 Data Access, please send...
       · Don't get me wrong the article is interesting. However, since it is broken in...
     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - 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

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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