Stored procedure validation

Results 1 to 2 of 2

Thread: Stored procedure validation

  1. #1
    Join Date
    Dec 1969

    Default Stored procedure validation

    I am having users enter a numeric value and on the submit I execute a stored procedure based on the value entered in order to bring additional data. This works fine, however when the value that is entered does not return any value I receive an error---I am trying to pop a message if the entered value does not return any data then to have the user re-verify the number.<BR>Any idease? (coding this in C#)

  2. #2
    Join Date
    Dec 1969

    Default RE: Stored procedure validation

    Lot&#039;s of ways to do this. You could return a Error from the stored proc to the calling c# program. In the c# code you put the call to the stored proc inside a try catch block.<BR><BR>try {<BR>// execute sp<BR>}<BR>Catch (SqlException e)<BR>{ <BR> String msg = "";<BR> switch (e.Number)<BR> { <BR> case 50001<BR> //user defiend error 1<BR> msg = "Oops error 1";<BR> break;<BR> case 50002<BR> //user defiend error 2<BR> msg = "Oops error 2";<BR> break;<BR><BR>Well you get the idea I think. To throw an error from inside the sp you use RAISERROR (check Books Online for more info)<BR><BR>so you could do:<BR><BR>IF @@ROWCOUNT = 0 <BR> RAISERROR (50001, 16, 1)<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts