Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm creating a system where I must deduct and add by one if the item is borrowed/returned. In my system I have 2 tables:

tblItems(_itemnumber_, _itemname_, _quantity_)
tblBorrow(_dateborrowed_, _datedue_, _status_)

Where if I borrowed an item the status will be borrowed and the quantity will deducted by 1 and if the status is returned the quantity will added by 1. This is my idea(I already how to add and update) but i don`t know how to code this idea. I'd really appreciate your help.

I`m using imports system.data.oledb
Posted

as it is, I cant see a relation in between the tables you show ..

so, for instance, using 'pseudo' SQL, Im thinking its like 'update tblItems set _quantity_ = _quantity_ - 1', and, you wish to do that 'where tblBorrow._status_ = 'borrowed''; (??)

If you had a link between those two tables, for say an _itemnumber_, I'd probably write say 2 stored procedures,

one for 'borrowed(_itemnumber)' which sets the _status_ and _quantity_, then another
for 'returned(_itemnumber_)' ditto status and quantity appropriately

but Im not very sure of your schema

'g'
 
Share this answer
 
You need to define relationship between these two tables using itemId so you can identify which item borrowed or which returned. After that define insert/update trigger on table tblBorrow.

please see this example in following blog

Trigger in Sql Server[^]
 
Share this answer
 
Comments
Member 10526674 16-Jan-14 6:35am    
sir thank you for your relply and i change the database. I add itemnumber in the tblBorrow so the relationship is now one is to one(itemnumber-itemnumber). is this enough to create some codes w/o error?

tblItems(_itemnumber_, _itemname_, _quantity_)
tblBorrow(_itemnumber_, _dateborrowed_, _datedue_, _status_)

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