ASP.NET
  Home arrow ASP.NET arrow Developing Methods for the StudentDB Class...
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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

Developing Methods for the StudentDB Class for ASP.NET 2.0
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-09-11

    Table of Contents:
  • Developing Methods for the StudentDB Class for ASP.NET 2.0
  • Creating the INSERT, UPDATE and DELETE methods
  • Explaining the code for the methods
  • Testing the Data Access Methods
  • The complete code for the Student and StudentDB Classes

  • 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


    Developing Methods for the StudentDB Class for ASP.NET 2.0


    (Page 1 of 5 )

    We developed two of the methods of the StudentDB class in the previous article. Today we continue developing other methods of that class. In particular we are going to develop the InsertStudent(), UpdateStudent() and DeleteStudent() methods along with their T-SQL stored procedures and the test web page.

    Let's start by creating the necessary stored procedures for the Students table. We need one stored procedure to insert a record into the table, another one to update records and a third one to delete a record from the table. The T-SQL code that you need to run in your SQL Server Management Studio is shown next.

    USE School
    GO
    CREATE PROCEDURE InsertStudent
    @StudentID INT OUTPUT,
    @FirstName NVARCHAR(20),
    @LastName NVARCHAR(20),
    @DateOfBirth DATETIME,
    @AdmissionDate DATETIME,
    @Major NVARCHAR(40),
    @Active BIT
    AS
    INSERT INTO Students
    (FirstName, LastName, DateOfBirth, AdmissionDate, Major, Active)
    VALUES
    (@FirstName, @LastName, @DateOfBirth, @AdmissionDate, @Major,
    @Active)
    SET @StudentID = SCOPE_IDENTITY()
    GO

    CREATE PROCEDURE DeleteStudent
    @StudentID INT
    AS
    DELETE FROM Students
    WHERE StudentID = @StudentID
    GO

    CREATE PROCEDURE UpdateStudent
    @StudentID INT,
    @FirstName NVARCHAR(20),
    @LastName NVARCHAR(20),
    @DateOfBirth DATETIME,
    @AdmissionDate DATETIME,
    @Major NVARCHAR(40),
    @Active BIT
    AS
    UPDATE Students
    SET FirstName = @FirstName,
    LastName = @LastName,
    DateOfBirth = @DateOfBirth,
    AdmissionDate = @AdmissionDate,
    Major = @Major,
    Active = @Active
    WHERE StudentID = @StudentID
    GO

    The first stored procedure, the InsertStudent procedure, accepts the student's record values and returns the Student ID as an output parameter using the SCOPE_IDENTITY() server function. This function returns the last identity value inserted in an identity column in the current scope; in our case the scope is the stored procedure. The second procedure simply deletes a record based on the StudentID column and the third stored procedure, the UpdateStudent procedure, is used to update a record based on the StudentID column as well. Now let's create the individual methods.

    More ASP.NET Articles
    More By Michael Youssef


       · Today we complete the StudentDB class, you need to read the previous 2 articles to ...
       · i used your code in my application and it's nice. thank you very much for the...
       · It would be better to use the code with the ObjectDataSource control and using a...
     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek