在我的页面中出现空引用错误,我不知道代码中的错误在哪里

时间:2014-07-14 10:37:35

标签: c# .net iis

我从早上发现了一个奇怪的问题。我在下面有一段代码

protected void Page_Load(object sender, EventArgs e)
{
this.Page.Session.Timeout = 40;
if (!this.Page.IsPostBack)
{
    if (!this.objCurrentSession.CanCurrentEmployeeChangePanNumber)
    {
        this.PanNumberTextBox.Enabled = false;
    }

    this.fUpdateFYLabels();
    this.fAddPropertyDropDownItems();
    this.fAddRentCityNames();
    //this.fAddPropertyHandlers();
    this.EmployeIDLabel.Text = this.objCurrentSession.CurrentEmployeeCode;
    this.EmployeeNameLabel.Text = this.objCurrentSession.CurrentEmployeeName.ToUpper();
    this.fGetEmployeeData();
    this.fGetInvestmentData();
}
DisableAllControls(this.Page, false);
}
private void fGetEmployeeData()
{
           using (SqlConnection objConn = new SqlConnection(this.objClientInfo.CompanyDBConnectionString))
    {
        using (SqlCommand objCmd = new SqlCommand())
        {
            objCmd.Connection = objConn;
            objCmd.CommandText = "SELECT * FROM [ess_EmpMaster] WHERE [empCode] = @empCode";
            objCmd.Parameters.Add(new SqlParameter("@empCode", System.Data.SqlDbType.VarChar));
            objCmd.Parameters["@empCode"].Value = this.objCurrentSession.CurrentEmployeeCode;

            objConn.Open();
            using (SqlDataReader objDR = objCmd.ExecuteReader())
            {
                if (objDR.Read())
                {
                    this.PanNumberTextBox.Text = objDR["PanNumber"].ToString();
                    this.PanNumberTextBox.Enabled 
                        = (bool.TrueString == objDR["IsPanNumberEnabled"].ToString());
                    this.GenderLabel.Text = objDR["Gender"].ToString();
                }
                objDR.Close();
                objConn.Close();
            }              

        }

        using (SqlCommand objHRACmd = new SqlCommand())
        {
            objHRACmd.Connection = objConn;
            objHRACmd.CommandText = "SELECT HouseRentAllowance FROM [ess_Flexideclarations] WHERE ID = (SELECT MAX(ID) from ess_Flexideclarations WHERE [empCode] = @empCode)";
            objHRACmd.Parameters.Add(new SqlParameter("@empCode", System.Data.SqlDbType.VarChar));
            objHRACmd.Parameters["@empCode"].Value = this.objCurrentSession.CurrentEmployeeCode;

            objConn.Open();
            HRA = (decimal)objHRACmd.ExecuteScalar();
            objConn.Close();
        }
        if (HRA <= 0)
        {
            this.HRSpan.Visible = HRTr.Visible = false;
        }
        else
        {
            this.HRSpan.Visible = HRTr.Visible = true;
        }
    }
}

但问题是在IIS中从实时URL打开时它会抛出黄屏错误。但是当我浏览代码时,我根本没有捕获任何空值。这些值在实时有效。我给你下面的错误截图。请检查并告诉我,我需要解决这个错误来解决这些问题。下面给出错误消息。

对象引用未设置为对象的实例。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.NullReferenceException:未将对象引用设置为对象的实例。

来源错误:

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

堆栈追踪:

[NullReferenceException: Object reference not set to an instance of an object.]
Employee_InvestmentDeclarationView.fGetEmployeeData() +686
Employee_InvestmentDeclarationView.Page_Load(Object sender, EventArgs e) +386
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.1022

提前致谢。

0 个答案:

没有答案