Testing the StudentDB Class for ASP.NET 2.0
(Page 1 of 5 )
In the first article of this series we created the database table, the Student class and sketched the structure of the StudentDB class. In this article, we start developing the methods of the StudentDB class and testing it from an ASP.NET web page.
In particular, we will develop the GetStudent() and GetStudentsInCollection() methods. I advice you to read my articles about ADO.NET before you continue reading this article if you are not familiar with ADO.NET.
We start by creating the stored procedures needed by the GetStudent() and GetStudentsInCollection() methods. Run the following T-SQL code in your SQL Server Management Studio:
USE School
GO
CREATE PROCEDURE GetStudent
@StudentID INT
AS
SELECT StudentID, FirstName, LastName, DateOfBirth,
AdmissionDate, Major, Active
FROM Students
WHERE
StudentID = @StudentID
GO
CREATE PROCEDURE GetAllStudents
AS
SELECT StudentID, FirstName, LastName, DateOfBirth,
AdmissionDate, Major, Active
FROM Students
This T-SQL code simply creates two stored procedures. The first one is GetStudent, which accepts a parameter of type INT as the Student ID and returns a student record based on that ID. The second stored procedure, GetAllStudents, returns all the records of the Students table.
Note that I have selected all the columns of the table using their individual column names and not using the asterisk (*). I like to do that because, if for some reason I have modified the structure of my table by adding more columns, I would not break my code. It depends on your situation and your business logic, but it's a good practice to use column names instead of the asterisk (*). Let's create the GetStudent() method.
Next: Creating the GetStudent() method >>
More ASP.NET Articles
More By Michael Youssef