kfox

kfox

  • NA
  • 3
  • 0

Do you think this is a legitimate use of GoTo in vb.net?

Jun 7 2007 5:53 PM

Do you think this is a legitimate use of GoTo in vb.net?  Does anyone have a better solution for this problem that creates a generic ExecuteNonQuery?
'==========================================================================

    Public Shared Function ReturnParameterNonQuery(ByVal sSql As String, _

        Optional ByVal p1 As String = "-9999", _

        Optional ByVal p2 As String = "-9999", _

        Optional ByVal p3 As String = "-9999", _

 '… continue for as many parameters as you would have maximum in your project.

 'of course this wouldn’t work if I had a legitimate value of “-9999”

        Optional ByVal p25 As String = "-9999", _

        Optional ByVal p26 As String = "-9999") As Int16

        'Test if these parameters have values.

        Dim conn As New DataAccess 'Connect to database

        Dim cmd As New OracleCommand(sSql, conn.getconn)

        If p1 = "-9999" Then

            GoTo NoMoreParameters

        Else

            cmd.Parameters.AddWithValue("p1", p1)

        End If

        If p2 = "-9999" Then

            GoTo NoMoreParameters

        Else

            cmd.Parameters.AddWithValue("p2", p2)

        End If

   … for as many parameters as you would have maximum in your project.

  If p26 = "-9999" Then

            GoTo NoMoreParameters

        Else

            cmd.Parameters.AddWithValue("p26", p26)

        End If

        'Don’t you think this is a legitimate use for a GoTo?  Saves time!

   NoMoreParameters:

        ReturnParameterNonQuery = cmd.ExecuteNonQuery()

        cmd.Dispose()

    End Function


Answers (2)