Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a aspx page which contain a textbox (txtStudentName) and a drop box (dropdownlistGroupName) and a save button

student table
    StudentID StudentName GroupID
       1         ABC        1
       2         DEF        1
       3         GHI        2

Group table   
GroupID      GroupName
    1           Pear
    2           Apple
    3           Strawberry

when i click on save button it will insert in student, saying that this student belong to this groupname

but at the save button.. how am i going to check / validate that this groupname like example Apple will only have 20 student belong to Apple group, if user click on saving the 21 student, it should prompt a message saying that this Apple group is full

i not sure how to i check with the database?

so what i should i do in the button backend code?


hope someone can tell me what should i do with some sample which will be nice and easy for me understand

thanks
Posted
Updated 6-Jan-12 21:48pm
v2

Select COUNT(*) as [No. of Students] from student where GroupID=1


Check the returned No. of students in code and flash message.
 
Share this answer
 
Comments
cutexxbaby 7-Jan-12 3:48am    
can you give me a much clear code that i should do in the button instead of just this one line?it will be really helpful to me, thank
cutexxbaby 7-Jan-12 3:50am    
like example where should i state the >20 then should a message to tell it cannot save
Try:
SQL
SELECT COUNT(*) AS InGroup FROM student WHERE GroupID=2




"can you give me a much clear code that i should do in the button instead of just this one line?it will be really helpful to me, thank"

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT COUNT(*) AS InGroup FROM student WHERE GroupID=2", con))
        {
        int count = com.ExecuteScalar())
        ...
        }
    }
 
Share this answer
 
v2
Comments
cutexxbaby 7-Jan-12 3:48am    
can you give me a much clear code that i should do in the button instead of just this one line?it will be really helpful to me, thank
OriginalGriff 7-Jan-12 4:02am    
Answer updated.
cutexxbaby 7-Jan-12 4:27am    
so i just need to call this code in the button , then i can check if student table groupID =1 ...but where should i indicate that cannot more than 20 student have groupID ...if the 21 student is going to be save, it should prompt a message to inform user
OriginalGriff 7-Jan-12 4:40am    
That bit is down to you! :laugh:
I don't know how your pages work - how would you display the "Done it" message, or any other?
cutexxbaby 7-Jan-12 5:54am    
no i mean WHERE in button should i indicate that count that cannot be more than 20, or i will prompt it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900