NullException错误, [英] NullException Error,

查看:121
本文介绍了NullException错误,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我需要帮助对NullException错误进行排序.代码如下.请告诉我有什么问题.错误提示:该函数未在所有代码路径上返回任何值.


*************存储过程-GetAccountByCat ************

使用[ERPFinAccounting]
GO
/******对象:StoredProcedure [dbo].[GetAccountByCat]脚本日期:01/16/2011 10:45:02 ******/
设置ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

更改过程[dbo].[GetAccountByCat]
@AccCat varchar(1)
AS

选择*从AccountsTable中,其中AccountCat = @AccCat


**************************来自类*********

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 *********

#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



**************************



**************************

推荐答案

返回必须在结束尝试",而不是在尝试"块内.

想一想.如果在Try和Return语句之间的代码中断,则没有其他Return语句可发送回值.

最好的做法是在一个函数中只包含一个Return语句.
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.


这有什么令人困惑的地方?将Return语句移至End Try语句之后.
What''s so confusing?? Move the Return statement to after the End Try statement.


这篇关于NullException错误,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆