0

Hi everyone,

I was wondering if anyone out there knows how to limit the number of entries into a DB. I'm trying to build a page that will allow users to sign up for a class. Each class has a limit of 20 students per session. Any kind of help will be greatly appreciated.

Thanks,
SK.

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by skhan1021
0

I would do two things:

on the front end when displaying the list of available classes, check the number of students already enrolled.

On the back end, use a stored procedure to add a student to a class
i would do it something like this.

sp_addStudent (@studentid int, @classid int) as
declare @count int
set @count = (select count(*) from tblClassroster where classid = @classid) 
if @count >19 
set @count = -2
else
insert into tblClassroster values (@classid, @studentid)
select (@count +1) as NumberInClass

then, after you try to insert the student you can check the returned field to see if it was successful and let the user know. (-1 means insert failed, otherwise the new number of students in the class)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.