Lecture – Using a DropdownList with a Database

Using a DropdownList with a Database

Summary

Demonstrates the example of creating a web form with a drop down list. The drop down list is populated from a database view. The return value is then used to call a database stored procedure. Also demonstrated is updating a view that is used in the project.

Prerequisite Lectures

Calling Stored Procedures from Visual Studio 1

Video

Code

UsesĀ Case Study – Registration Database

View
view_courses
CREATE view [dbo].[view_courses]
AS
SELECT
CourseOffering.id,
term_identifier + [Year] + ‘ ‘ +Prefix + Number as ‘Course’
FROM
Courses, CourseOffering, Semesters
WHERE
Courses.id = CourseOffering.CourseIDĀ AND
Semesters.id = COurseOffering.SemesterID</br>
View
view_student
create view [dbo].[view_student]
AS
SELECT
id,
FirstNameText + ‘ ‘ + LastnameText as ‘Name’
FROM
Students</br>
Stored
Procedure
create procedure [dbo].[sp_registerStudent]
@StudentID int,
@CourseOfferingID int
AS
BEGIN
INSERT INTO StudentEnrollment
(StudentID, CourseOfferingID)
VALUES
(@StudentID, @CourseOfferingID)
END