468,556 Members | 2,009 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,556 developers. It's quick & easy.

Redirect based on stored procedure return values

I have a stored procedure which returns a value of between 0 and 4.

I want the user to press a button to receive feed back on their last input.

The save button takes the input and saves it to the database. The feedback
button runs a stored proc that takes the saved data from the table, performs
a logical calcualation and returns the right value between 0 and 4. Depending
on the value returned the redirect page is different.

Here is the code thats is activated when the save button is clicked:

Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Save.Click
AddbslCmd.Parameters.Add("@username", txtCookie.Text)
AddbslCmd.Parameters.Add("@bsl", txtBsl.Text)
SqlConnection1.Open()
AddbslCmd.ExecuteNonQuery()
SqlConnection1.Close()

lblStatus.Text = "Blood Sugar Level saved"

End Sub

and here is the code for when the feedback button is clicked:

Private Sub feedback_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles feedback.Click

GetFeedbackCmd.Parameters.Add("@username", txtCookie.Text)
SqlConnection1.Open()
GetFeedbackCmd.ExecuteNonQuery()

If GetFeedbackCmd.Parameters("@Return_Value").Value = 0 Then
Response.Redirect("lowerfeedack.aspx")

ElseIf GetFeedbackCmd.Parameters("@Return_Value").Value = 1 Then

Response.Redirect("highfeedback.aspx")

ElseIf GetFeedbackCmd.Parameters("@Return_Value").Value = 2 Then

Response.Redirect("vhighfeedback.aspx")

ElseIf GetFeedbackCmd.Parameters("@Return_Value").Value = 3 Then

Response.Redirect("dangerousfeedback.aspx")

ElseIf GetFeedbackCmd.Parameters("@Return_Value").Value = 4 Then

Response.Redirect("ontargetfeedback.aspx")

End If

End Sub

When I run the page the data is saved on clicking the save button but no
matter what value the stored proc returns the page always redirects as if the
return value is 1

Does this make sense? I can clarify further if needed
How can i adjust the code so that the redirect works as it should?

Nov 19 '05 #1
3 2078
That code looks extremely ugly.
Try something like this.
Dim RetVal as Integer =
GetFeedbackCmd.Parameters("@Return_Value").Value
Dim Redirect as String
Response.Write("WE got a return value of " + RetVal + "<br />")
select case RetVal
case 1: Redirect = "bleah"
case 2: Redirect = "help"
end select

response.write("We are redirecting to " + Redirect + "<br />")
' Response.Redirect(Redirect)
' uncomment the above line after verifying all of the input is actually
what you think it is. and not something else
' My exact syntax for the select statement may be off so please confer
to your existing knowledge of vb.net or the vb.net manual. Make sure
that you put a statement to terminate so that it does not bounce
through.
' You should also probably add a default or case else to handle all
other values.

' Hope this helps

Nov 19 '05 #2
I'm a bit of a beginner at this.

MY code was made to be a simple as possible. Can you tell me why my original
code doesn't work?

if possible could you explain what your code is doing and what each case is
supposed to be and where exactly i pt in each page that the user can be
redirected to?

thanks

"re****@community.nospam" wrote:
That code looks extremely ugly.
Try something like this.
Dim RetVal as Integer =
GetFeedbackCmd.Parameters("@Return_Value").Value
Dim Redirect as String
Response.Write("WE got a return value of " + RetVal + "<br />")
select case RetVal
case 1: Redirect = "bleah"
case 2: Redirect = "help"
end select

response.write("We are redirecting to " + Redirect + "<br />")
' Response.Redirect(Redirect)
' uncomment the above line after verifying all of the input is actually
what you think it is. and not something else
' My exact syntax for the select statement may be off so please confer
to your existing knowledge of vb.net or the vb.net manual. Make sure
that you put a statement to terminate so that it does not bounce
through.
' You should also probably add a default or case else to handle all
other values.

' Hope this helps

Nov 19 '05 #3
The code does not work, because you do not understand it.
You have no checks in there to verify that you are getting the values
that it is going.
You probably do not even know what path it is going.

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Bill Kellaway | last post: by
7 posts views Thread by Philip Mette | last post: by
4 posts views Thread by scparker | last post: by
9 posts views Thread by fniles | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.