No value will be returned if an exception is added to this try..catch file. You must either provide a return value if an exception occurs (returning something in any catch block, or you need to rebuild the exception.
Public Function getkey(ByVal id As String) Dim cmd As SqlCommand Try cmd = New SqlCommand("dbo.getkeydesc", GenLog.cn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@id", id) Dim r As SqlDataReader = cmd.ExecuteReader() If r.HasRows Then Return True Else Return False End If Catch ex As Exception MsgBox(ex.ToString) ' Either do this: ' Return False ' or this: ' Throw ex Finally ' If Not cn Is Nothing Then cn.Close() End Try End Function
Bas source share