Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, So I am having a library management system that let students add books to their table I want to set the maximum books that student can add is 5???

What I have tried:

So I have tried to give each student added a max books column that has int 0 when a student adds a book the int will equal 1 ........ to a 5 when it will be 5 it will return a message.. the question is how do I set the max value 5?
Posted
Updated 16-May-21 4:49am
Comments
Richard MacCutchan 16-May-21 7:08am    
How are you storing the books in the student's database entry?
Omar Dakelbab 16-May-21 7:09am    
I created a table that stores all added books by students inside that table i have book_ID, student_ID and the dateTime
Omar Dakelbab 16-May-21 7:12am    
So when student add book column(maxBooks) = maxBooks + 1; when maxbooks = 5 return a message

In WPF you can use ValidationRule, see example here:
How to set Minvalue and Max Value for a testbox in wpf[^]

Or use this custom NumericUpDown control: Creating a NumericUpDown control from scratch[^]

If you want to do it in SQL use a Constraint, see: SQL constraint minvalue / maxvalue? - Stack Overflow[^]
 
Share this answer
 
v3
Comments
Omar Dakelbab 16-May-21 6:54am    
thanks for the reply but i want to set the max value in the SQL table
Controlling the amount of rows in the database is a bit more tricky because you cannot do it using a simple constraint. Constraints work only on row level, for example like NOT NULL constraint.

However, using T-SQL programming and a trigger you can enforce the business logic you want, even for a set of rows. For an example you might want to read Control maximum number of rows in a table[^]
 
Share this answer
 
SQL COUNT(), AVG() and SUM() Functions[^]. So something like:
SQL
SELECT COUNT(Books) FROM BookTable WHERE student_Id = this student's id;

If the returned value is 5 then reject the request.
 
Share this answer
 
Comments
Omar Dakelbab 16-May-21 14:02pm    
Thanks for the reply

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