Redirect based on stored procedure return values

G

Guest

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?
 
R

recoil

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
 
G

Guest

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
 
R

recoil

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top