在'Try'块中执行后生成的NullReferenceException

时间:2015-02-26 07:00:38

标签: c# nullreferenceexception

我是ASP.net C#的新手。我有一个应用程序来获取用户的输入并保存在数据库中。我根据要求在N层架构中创建了这个应用程序。我在代码隐藏中创建了一个对象,并将输入值设置为它们,并将对象传递给业务层中的方法,并将数据访问层中的方法称为业务层。数据以数据访问层的方法保存到数据库中。请帮忙。

这是我的代码隐藏:

try
{
    OtherCompany om = new OtherCompany();
    NDAStaff ns = new NDAStaff();

    DateTime dt = Convert.ToDateTime(RadDatePicker1.SelectedDate);
    om.Date = dt.ToShortDateString();
    om.ComName = compName.Text;
    om.RegNumber = compReg.Text;
    om.Country = countryIncorp.Text;
    om.RegOfficeAddress = officeAddr.Text;
    om.ComRef = compRef.Text;
    om.CoreBuss = busiCore.Text;
    om.ComService = reqServ.Text;

    int index = servList.Items.Count;
    for (int i = 0; i < index; i++)
    {
        om.ReqServiceDetails[i] = servList.Items[i].Value;
    }

    om.ReprentName = fullName2.Text;
    om.ReprentDesig = desigOther.Text;
    om.Witness1Name = witFullName3.Text;
    om.Witness1Desig = witDesig1.Text;
    om.Witness1Address = witDept1.Text;
    om.Witness2Name = witFullName4.Text;
    om.Witness2Desig = witDesig4.Text;
    om.Witness2Adress = witAddr4.Text;

    ns.Staffname = fullName1.Text;
    ns.Designation = desigSriLan.Text;
    ns.Wit1Name = witFullName1.Text;
    ns.Wit1Designation = witDesig1.Text;
    ns.Wit1Department = witDept1.Text;
    ns.Wit2Name = witFullName2.Text;
    ns.Wit2Designation = witDesig2.Text;
    ns.Wit2Department = witDept2.Text;


    NDAGenProcessor ndap = new NDAGenProcessor();
    OtherCompanyProcessor ocp = new OtherCompanyProcessor(om);
    NDAstaffProcessor nsp = new NDAstaffProcessor();


    int NADid = ocp.createNDAID();
    //ndap.createPDF(om, ns, NADid);
    ocp.getCompanyDetails(NADid);
    nsp.addNDAstaffData(ns, NADid);
}

catch (Exception ex)
{
    throw ex;
}

1 个答案:

答案 0 :(得分:0)

如果您想知道哪一行代码导致异常,请转到Debug-&gt; Exceptions并选中Thrown Common Language Runtime Exceptions框。

你将获得所谓的First Chance Exception。然后调试你的代码,调试器将停在导致异常的那一行。