How do I add code to redirect my user on successful submit to my database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dibblejon
    New Member
    • Apr 2010
    • 1

    #1

    How do I add code to redirect my user on successful submit to my database?

    Any help would be really helpful.

    Code:
    Imports System.Data
    Imports System.Data.SqlClient
    Partial Class CPD_OnlineSurvey
        Inherits System.Web.UI.Page
    
        Public Sub UpdateOnlineSurvey(ByVal sender As Object, ByVal e As EventArgs)
            Using conn As New SqlConnection()
                conn.ConnectionString = ConfigurationManager _
                            .ConnectionStrings("wincts").ConnectionString
                Using cmd As New SqlCommand()
                    cmd.CommandText = "update OnlineSurvey set IsSelected = " & _
                                      "@IsSelected where QuestionId=@QuestionId"
                    cmd.Connection = conn
                    conn.Open()
                    For Each item As ListItem In ChkOnlineSurvey.Items
                        cmd.Parameters.Clear()
                        cmd.Parameters.AddWithValue("@IsSelected", item.Selected)
                        cmd.Parameters.AddWithValue("@QuestionId", item.Value)
                        cmd.ExecuteNonQuery()
                    Next
                    conn.Close()
                End Using
            End Using
        End Sub
    End Class
  • semomaniz
    Recognized Expert New Member
    • Oct 2007
    • 210

    #2
    use a try catch block and then right after the next statement user Response.Redire ct (" ").

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Dibblejon, in the future could you please ask the question in thread instead of just in the title the thread? It's a little confusing when there's no question and a bunch of code posted in the thread.

      Anyways, semomaniz has made a great recommendation.
      The ExecuteNonQuery Method will throw an exception if anything goes wrong...so that's one way to check if the data was successfully submitted. The ExecuteNonQuery method returns an Integer that specifies the number of rows affected by the query. If this number is 0 then you know that the update also didn't work....

      -Frinny

      Comment

      Working...