Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,


Actually i have written a trigger on a table.when we want to insert data into that table the trigger fires based on the condition given.here is the point what i want to do is i have to display the message( what the trigger gives) in a message box in the application(which is running).





Thank you,
Posted

This doesn't looks like a correct design to me. You cam modify the insert stored procedure and return the message from there. Or, your trigger must be writing that message in an audit table or something similar. So once the insert is done, read the audit table and get the message from there.

BTW what does this trigger do? And what kind of message you want to display?

Update: Bad design. Sorry. This should be checked in the UI and in the BusinessLogic before doing the save. This check should also be placed in the stored procedure doing the insert. Both BusinessLogic and SP should throw an exception to tell that the price is not correct. Something custom preferably like BusinessValidationException.

Your UI should then handle this exception and show the message to the user.

You do not need and cannot use trigger for that (assuming values over 1000 are not stored in the column).

Update 2: You do not have to wait till incorrect data reaches DB. Check it in the UI, check it in the BusinessLayer and then check it in the DB as well. This is how it should be done. UI can show the validation message to the user. BusinessLayer and DB have to tell the UI that the data is wrong. This can either be done through a return value from the methods or through exceptions. Triggers are not for this purpose.
 
Share this answer
 
v4
Comments
lakshmanriz 6-Apr-11 4:36am    
well.i want a column called 'price'.In that if any one enters a value more than 1000 the trigger has to fire and it has to display a message related to that(like "you have entered more than 1000" in the application)
dan!sh 6-Apr-11 4:44am    
Updated the reply.
zan0701 6-Apr-11 4:43am    
you can do it at UI level itself. In fact it would be better because it will display message as soon as user enters more than 1000 and then it will be stored in database and trigger will run. I still wonder why you want to display message after trigger only.
lakshmanriz 6-Apr-11 7:38am    
when any one wants to insert data in data base trigger fires(according to condition).that time i have to display a message.
dan!sh 6-Apr-11 8:18am    
Updated the reply.
One way is that you use a separate table. Add the messages to this table in the trigger, for example:
INSERT INTO Messages (...) VALUES (.., 'Something from the trigger')
And after the operation is done, read the contents of the table from the client.

However, based on your example you should not create a design like this to get confirmations from client. The basic rules of ACID is that conversations with the user go like this:
1. Validity checks, possible questions
2. start transaction
3. execute dml operations
4. commit/rollback
5. inform the user

So there's no conversation, never, with the user while the transaction is active. If this golden rule is broken, you'll end up to serious locking based problems.
 
Share this answer
 
Comments
lakshmanriz 7-Apr-11 1:21am    
do you mean at the time of trigger fires we can not display a message to the user?
Wendelius 7-Apr-11 13:43pm    
Yes I do. Technically it's possible but it should never be done. No user conversations while transaction is active.
lakshmanriz 8-Apr-11 1:18am    
Thanks for your reply.Actually we have a device which accepts finger print data.whenever a user put his finger on the device,that will be stored in the database.at the time of storing we need to send a message to the user's mobile.Hope you can understand

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