The Catch section is always executed even if the Try section has been executed. I am trying to send the user to one page if the delete worked properly and a different page if the delete did not work because of relationships between tables:
Protected Sub btnDeleteBuilding_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDeleteBuilding.Click
Session("sesBuilding")=txtBuilding.Text
Dim objConnection As New SqlConnection(WebConfigurationManager.ConnectionStrings("TonerRequest").ConnectionString)
Try
Dim strSQL As String
strSQL = "DELETE FROM Building WHERE BuildingID = " & Session("sesBuildingID")
objConnection.Open()
Dim objCommand As New SqlCommand(strSQL, objConnection)
objCommand.ExecuteNonQuery()
Response.Redirect("Building_Deleted.aspx")
Exit Try
Catch
Response.Redirect("Building_Not_Deleted.aspx")
Finally
objConnection.Close()
End Try
End Sub