Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function question/problem

Status
Not open for further replies.

PsychoCoder

Programmer
May 31, 2006
140
US
In my application I have the following function:
Code:
Public Function GetGMTOffset(ByVal sAirport As String) As Double
        Dim dOffset As Double
        sSQL = "EXECUTE ama_GetGMTOffset "
        cmdCommand = New SqlCommand(sSQL, cnConnection)
        cmdCommand.Parameters.AddWithValue("@airport", sAirport)
        Try
            cnConnection.Open()
            dOffset = cmdCommand.ExecuteScalar
            Return dOffset
        Catch exSQL As SqlException
            MsgBox(SQL_EXCEPTION, MsgBoxStyle.Critical, "Database Error")
        Catch exSQLTimeout As TimeoutException
            MsgBox(SQL_TIMEOUT, MsgBoxStyle.Critical, "Timeout Error")
        Catch exApp As ApplicationException
            MsgBox(APP_EXCEPTION, MsgBoxStyle.Critical, "Application Error")
        Catch ex As Exception
            MsgBox(GENERAL_EXCEPTION & ex.Message, MsgBoxStyle.Critical, "General Error")
        Finally
            cnConnection.Close()
        End Try
    End Function

This function is called in a seperate function:
Code:
Public Function ConvertGMT(ByVal dLocalDate As DateTime, ByVal sAirport As String) As DateTime
        _dGMTTime = DateAdd(DateInterval.Hour, CType(GetGMTOffset(sAirport), Double), dLocalDate)
        Return _dGMTTime
    End Function

But when the code is ran the GetGMTOffset jumps straight to the Catch exSQL As SqlException
MsgBox(SQL_EXCEPTION, MsgBoxStyle.Critical, "Database Error")
line. Am I not using ExecuteScalar correctly?

Any ideas?

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
ThatRickGuy,

Now I feel real stupid lol. I forgot I was throwing my own custom message, I changed the SQL_EXCEPTION variable to exSql.Message and got the error and was able to fix it. Thanks


Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top