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.

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)

Thanks. I will give it a shot.

I appreciate your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.