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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
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

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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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

    - 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...
    - Order-Related Modules for an ASP.NET AJAX Se...
    - User and Role Management for an ASP.NET AJAX...
    - Programming an ASP.NET AJAX Server-Centric B...





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