Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
application flow in SQL SERVER SPROC
21-12-2004, 01:03 PM
Post: #1
application flow in SQL SERVER SPROC
I am relatively new to writing stored procedures for SQL SERVER so this probably a fairly basic one.....

I have an online order process that I am writing using C# and when it comes to filling out the new user registration form, what I am wanting to do is check that the username / email address entered is unique and if it is, submit the new users details to the users table, get the id number for the new user record created and enter a new record in the orders table. If the user name or email does already exist I want the sproc to return an error message to the C# code and terminate without doing the updates... Does anyone have any examples of a basic sproc to acheive this or can anyone point out any of the code terms that I should be looking up? I know that @@identity is the way I should be going in terms of getting the customer ID and putting it into the orders table but am not sure about termininating the sproc if a certain condition is false....

Check Out Car Hire in Leeds and don't forget to check out my personal blog Fearless Shultz
Send this user an email Find all posts by this user
Quote this message in a reply
21-12-2004, 01:10 PM
Post: #2
 
If you have an identity column which allows no dupliucates, C# will actually throw an error if you try to insert a duplicate value.

In this case, you can wrap the sqlcommand object in a try {} catch{} block to catch the error, and output a friendly error message.

Bomberman
aka Colin Smith
http://www.smithcolin.co.uk
Send this user an email Visit this user's website Find all posts by this user
Quote this message in a reply
21-12-2004, 01:44 PM
Post: #3
 
Thanks for the Reply Bomber I give that a try. That is actually a lot more straight forward than the way I was thinking it would have to be done.

Check Out Car Hire in Leeds and don't forget to check out my personal blog Fearless Shultz
Send this user an email Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: