VB.NET End Sub statement causes code to jump backwards
<p>I have an asp.net web application that inserts information from the web form to a MS SQL database and returns the entry id that is created for the row. I accomplish this in the vb.net code behind. When the code reaches the "End Sub" command, the code execution will jump back up to an earlier line and runs the lines again. This causes two rows to be entered into the database. upon reaching "End Sub" a second time, the sub does end.</p>

<pre><code>    Protected Sub SubmitForm() Handles SubmitButton.ServerClick
    'Declare Variables
    'i have deleted this part from this post as i am over the char limit

    'Set values on variables
    'i have deleted this part from this post as i am over the char limit


    'Set connection string
    Dim setCmd As New SqlCommand
    sConnectionString = "Password=passwordhere;User ID=userhere;" &amp; _
                        "Initial Catalog=databasehere;" &amp; _
                        "Data Source=serverhere"
    Dim objConn As New SqlConnection(sConnectionString)

    'Connect to database
    Try
        objConn.Open()
    Catch Ex As Exception
        Select Case Ex.ToString
            Case "InvalidOperationException"
                Exit Try
            Case "SqlException"
                MsgBox("The database is currently down. Please try again in a few minute. " &amp; vbNewLine &amp; "If the issue persists please alert your supervisor.")
                Exit Sub
        End Select
    End Try

    'Set the stored proc
    sStoredProcName = "storedprocnamehere"
    setCmd = New SqlCommand(sStoredProcName, objConn)
    setCmd.CommandType = CommandType.StoredProcedure

    'Set the parameters that cannot be null
    'I do set all of the needed parameters, however i have deleted them from this post as i am over the char limit

    lReportNum = setCmd.ExecuteScalar()

End Sub
</code></pre>

<p>At this point it jumps to the line right before  lReportNum = setCmd.ExecuteScalar() and runs through the line again.</p>

<p>This happens even when I deploy the code and access the page on our intranet.</p>

<p>I am using Visual Studios 2010 and .net 3.5</p>

<p>Please help! I have been struggling with this and scouring the web for answers for two days.</p>

<p>Shawn</p>