Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Messages from Database

Status
Not open for further replies.

demopro

Programmer
Apr 23, 2001
117
US
Hello,

I have a vb.net application that holds canned queries that a user can run. My question is this. Does SQL server and VB.NET share messages on the code working, not working and what not?
I want to be able to rely the message to the user that a update, insert delete completed or did not complete.

Thanks,
Demopro
 
Enclose your insert, update and delete code in a Try...Catch block. Any error thrown by any of the insert, update or delete commands can be captured and displayed to the user. Throw in Transactions and you can do a rollback if any of the commands fail.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
I do have the code included in a [try...catch] where it can inform me of an error, but what about if it completed. I would like to give the user a confirmation that it worked.
 
Your user will quickly tire of the confirmation that something worked message

However you coold easily do what you want by the use of a boolean variable, which you set to True in the Catch loop. Outside the try-catch, you could check the variable for being False indicating nothing went wrong, and you could paint the form in flashing colours or whatever your heart desires.


Sweep
...if it works dont mess with it
 
If the "canned queries" are stored procedures you can use return codes.

0 Successful execution.
1 Required parameter value not specified.
2 Invalid parameter value specified.
3 Error occurred getting sales value.
4 NULL sales value found for the title.

If the "canned queries" are coded into the client side application then you will have to use the try... catch. You can specifially catch the sql exceptions.

Example of catching SQLException...

Try
MyCommand.ExecuteNonQuery()
Catch Exc As SQLException
Message.InnerHtml = "ERROR: Could not delete record"
Message.Style("color") = "red"
End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top