Click here to Skip to main content
15,895,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!

I need help to sort NullException Error. The code is as given below. Pls. tell me what can be wrong. The error says: the function doesn't return any value on all code paths.


************* Stored procedure - GetAccountByCat************

USE [ERPFinAccounting]
GO
/****** Object: StoredProcedure [dbo].[GetAccountByCat] Script Date: 01/16/2011 10:45:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[GetAccountByCat]
@AccCat varchar(1)
AS

SELECT * FROM AccountsTable WHERE AccountCat = @AccCat


*********************** from class *********

VB
#Region "GetAccountDetail - Return Information about all Accounts"
        Public Function GetAccountDetail(ByVal cat As String) As DataSet
            Dim localDSOutput As DataSet
            Dim ParamsStoredProcedure As String = "GetAccountByCat"
            Try
                Dim localOutPutServer As New DataServer(PrivateConnectionString)
                localOutPutServer.BuildParameter( _
                "@AccCat", cat, DataServer.SQLDataType.SQLChar, , ParameterDirection.Input)
                localDSOutput = localOutPutServer.returnDataSet(ParamsStoredProcedure)
                Return localDSOutput
            Catch ExceptionObject As Exception
                'LogException(ExceptionObject)
            Finally
            End Try
        End Function


**************************
Posted
Comments
OriginalGriff 16-Jan-11 2:43am    
Since you have posted your reply as both a comment to Dave and an answer, I have deleted the answer. Just use the comments, please, unless you solve the problem yourself and wish to post that as a solution for others with the same problem to see.

The Return has to go after the End Try, not inside the Try block.

Think about it. If your code between Try and your Return statement breaks, there is no other Return statement to send back a value.

It's also best practice to have only one Return statement in a Function.
 
Share this answer
 
Comments
kumarsajith01 16-Jan-11 2:04am    
Dear Dave,

Is it Ok, if I give - Return localDSOutput - after end try? I'm cnfused. Pls. help me.

Thanks!
Manfred Rudolf Bihy 16-Jan-11 8:08am    
Good call! 5+
I'll second that about the SPOE (Single Point Of Exit) part.
What's so confusing?? Move the Return statement to after the End Try statement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900