Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取对象引用未设置为附加业务层代码的对象实例_C#_Asp.net_.net - Fatal编程技术网

C# 获取对象引用未设置为附加业务层代码的对象实例

C# 获取对象引用未设置为附加业务层代码的对象实例,c#,asp.net,.net,C#,Asp.net,.net,我有一个业务层/Contactentry.ascx页面,它调用一个存储的prcoedure将数据插入sql数据库,然后下面的页面调用这个业务层方法。问题在于这种方法 aspdotnet.BusinessLogicLayer.ContactEntry AddEntry = new ContactEntry(Convert.ToInt32(Session["ContactID"].ToString()) ,Title,FirstName,MiddleName,LastName,J

我有一个业务层/Contactentry.ascx页面,它调用一个存储的prcoedure将数据插入sql数据库,然后下面的页面调用这个业务层方法。问题在于这种方法

aspdotnet.BusinessLogicLayer.ContactEntry  AddEntry = 
    new ContactEntry(Convert.ToInt32(Session["ContactID"].ToString())
    ,Title,FirstName,MiddleName,LastName,JobTitle,Company,Website,OfficePhone
    ,HomePhone,Mobile,Fax,OEmail,PEmail,OAStreet,OACity,OAState,OACountry
    ,OAZipCode,PAStreet,PACity,PAState,PACountry,PAZipCode);
抛出一个错误,说明object refernece未设置为对象的实例,尽管我已为文本字段输入了所有值

using System;
using System.Data;
using System.Configuration;
using aspdotnet.DataAccessLayer;

namespace  aspdotnet.BusinessLogicLayer
{
    public class ContactEntry
    {
        private int _ContactID;
        private string _Title;
        private string _FirstName;
        private string _MiddleName;
        private string _LastName;
        private string _JobTitle;
        private string _Company;
        private string _Website; 
        private string _OfficePhone; 
        private string _HomePhone; 
        private string _Mobile; 
        private string _Fax; 
        private string _OEmail;
        private string _PEmail;
        private string _OAStreet;
        private string _OACity; 
        private string _OAState; 
        private string _OACountry;
        private string _OAZipCode;
        private string _PAStreet; 
        private string _PACity; 
        private string _PAState; 
        private string _PACountry;
        private string _PAZipCode;

        public int ContactID
        {
            get { return _ContactID; }
            set { _ContactID = value; }
        }
        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }
        public string FirstName
        {
            get { return _FirstName; }
            set { _FirstName = value; }
        }
        public string MiddleName
        {
            get { return _MiddleName; }
            set { _MiddleName = value; }
        }
        public string LastName
        {
            get { return _LastName; }
            set { _LastName = value; }
        }

        public string JobTitle
        {
            get { return _JobTitle; }
            set { _JobTitle = value; }
        }

        public string Company
        {
            get { return _Company; }
            set { _Company = value; }
        }

        public string Website
        {
            get { return _Website; }
            set { _Website = value; }
        }

        public string OfficePhone
        {
            get { return _OfficePhone; }
            set { _OfficePhone = value; }
        }
        public string HomePhone
        {
            get { return _HomePhone; }
            set { _HomePhone = value; }
        }
        public string Mobile
        {
            get { return _Mobile; }
            set { _Mobile = value; }
        }
        public string Fax
        {
            get { return _Fax; }
            set { _Fax = value; }
        }
        public string OEmail
        {
            get { return _OEmail; }
            set { _OEmail = value; }
        }
        public string PEmail
        {
            get { return _PEmail; }
            set { _PEmail = value; }
        }

        public string OAStreet
        {
            get { return _OAStreet; }
            set { _OAStreet = value; }
        }

        public string OACity
        {
            get { return _OACity; }
            set { _OACity = value; }
        }
        public string OAState
        {
            get { return _OAState; }
            set { _OAState = value; }
        }
        public string OACountry
        {
            get { return _OACountry; }
            set { _OACountry = value; }
        }
        public string OAZipCode
        {
            get { return _OAZipCode; }
            set { _OAZipCode = value; }
        }
        public string PAStreet
        {
            get { return _PAStreet; }
            set { _PAStreet = value; }
        }
        public string PACity
        {
            get { return _PACity; }
            set { _PACity = value; }
        }
        public string PAState
        {
            get { return _PAState; }
            set { _PAState = value; }
        }

        public string PACountry
        {
            get { return _PACountry; }
            set { _PACountry = value; }
        }

        public string PAZipCode
        {
            get { return _PAZipCode; }
            set { _PAZipCode = value; }
        }
        public ContactEntry()
        {
        }
        public ContactEntry(int ContactID, string Title, string FirstName, string MiddleName, string LastName, string JobTitle, string Company, string Website, string OfficePhone, string HomePhone, string Mobile, string Fax, string OEmail, string PEmail, string OAStreet, string OACity, string OAState, string OACountry, string OAZipCode, string PAStreet, string PACity, string PAState, string PACountry, string PAZipCode)
        {

             _ContactID=ContactID; 
             _Title=Title;
             _FirstName = FirstName;
             _MiddleName = MiddleName;
             _LastName = LastName;
             _JobTitle = JobTitle;
             _Company = Company;
             _Website = Website;
             _OfficePhone = OfficePhone;
             _HomePhone = HomePhone;
             _Mobile = Mobile;
             _Fax = Fax;
             _OEmail=OEmail;
             _PEmail=PEmail;
             _OAStreet = OAStreet;
             _OACity = OACity;
             _OAState = OAState;
             _OACountry =OACountry;
             _OAZipCode = OAZipCode;
             _PAStreet = PAStreet;
             _PACity = PACity;
             _PAState = PAState;
             _PACountry = PACountry;
             _PAZipCode = PAZipCode;
        }

        public bool Save()
        {   
            if (_ContactID == 0)
                return Insert();
           else
              return  Update();
        }

        private bool Insert()
        {
            _ContactID = Convert.ToInt32(DBTask.ExecuteScalar(System.Configuration.ConfigurationManager.AppSettings[Web.Global.CfgKeyConnString], "ContactInfo_Insert", _Title, _FirstName, _MiddleName, _LastName, _JobTitle, _Company, _Website, _OfficePhone, _HomePhone, _Mobile, _Fax, _OEmail, _PEmail, _OAStreet, _OACity, _OAState, _OACountry, _OAZipCode, _PAStreet, _PACity, _PAState, _PACountry, _PAZipCode));
        return (0 < _ContactID);
        }
        public static void Remove(int ContactID)
        {           
        DBTask.ExecuteNonQuery(System.Configuration.ConfigurationManager.AppSettings[Web.Global.CfgKeyConnString], "ContactInfo_Delete", ContactID);
        }
        private bool Update()
        {
            try
            {
                DBTask.ExecuteNonQuery(System.Configuration.ConfigurationManager.AppSettings[Web.Global.CfgKeyConnString], "ContactInfo_Update", _ContactID, _Title, _FirstName, _MiddleName, _LastName, _JobTitle, _Company, _Website, _OfficePhone, _HomePhone, _Mobile, _Fax, _OEmail, _PEmail, _OAStreet, _OACity, _OAState, _OACountry, _OAZipCode, _PAStreet, _PACity, _PAState, _PACountry, _PAZipCode);             
                return true;
            }
            catch 
            {
                return false;
            }
        }
        public void  LoadContact(int ContactID)
        {
            DataSet ds = DBTask.ExecuteDataset(System.Configuration.ConfigurationManager.AppSettings[Web.Global.CfgKeyConnString], "ContactInfo_GetContact", ContactID);
            DataRow row = ds.Tables[0].Rows[0];         
            _ContactID=Convert.ToInt32(row["ContactID"].ToString()); 
            _Title=row["Title"].ToString();  
            _FirstName = row["FirstName"].ToString();  
            _MiddleName = row["MiddleName"].ToString();  
            _LastName = row["LastName"].ToString();  
            _JobTitle = row["JobTitle"].ToString();  
            _Company = row["Company"].ToString();
            _Website = row["Website"].ToString();
            _OfficePhone = row["OfficePhone"].ToString();
            _HomePhone =  row["HomePhone"].ToString();
            _Mobile =  row["Mobile"].ToString();
            _Fax = row["Fax"].ToString();
            _OEmail=row["OfficialEmail"].ToString();
            _PEmail=row["PersonalEmail"].ToString();
            _OAStreet = row["OAStreet"].ToString();
            _OACity = row["OACity"].ToString();
            _OAState = row["OAState"].ToString();
            _OACountry =row["OACountry"].ToString();
            _OAZipCode = row["OAZip"].ToString();
            _PAStreet = row["PAStreet"].ToString();
            _PACity = row["PACity"].ToString();
            _PAState = row["PAState"].ToString();
            _PACountry = row["PACountry"].ToString();
            _PAZipCode = row["PAZip"].ToString();           

        }

    }
}



Insert form calling above function from Business Layer:

private void btnSave_Click(object sender, System.EventArgs e)
        {
            string Title =  drplstTitle.SelectedItem.Text;    
            string FirstName = txtFirstName.Text;
            string MiddleName = txtMiddleName.Text;
            string LastName = txtLastName.Text;
            string JobTitle = this.txtJobTitle.Text;
            string Company = this.txtCompany.Text;
            string Website = this.txtWebSite.Text;
            string OfficePhone = this.txtOfficePhone.Text;
            string HomePhone = this.txtHomePhone.Text;
            string Mobile = this.txtMobile.Text;
            string Fax = this.txtFax.Text;
            string OEmail = this.txtOfficialEmail.Text;
            string PEmail = this.txtPersonalEmail.Text;
            string OAStreet = this.txtOAStreet.Text;
            string OACity = this.txtOACity.Text ;
            string OAState = this.txtOAState.Text;
            string OACountry = this.txtOACountry.Text;
            string OAZipCode = this.txtOAZipCode.Text;
            string PAStreet = this.txtPAStreet.Text;
            string PACity = this.txtPACity.Text;
            string PAState = this.txtPAState.Text;
            string PACountry = this.txtPACountry.Text;
            string PAZipCode = this.txtPAZipCode.Text;
            aspdotnet.BusinessLogicLayer.ContactEntry  AddEntry = 
new ContactEntry(Convert.ToInt32(Session["ContactID"].ToString()),Title,FirstName,MiddleName,LastName,JobTitle,Company,Website,OfficePhone,HomePhone,Mobile,Fax,OEmail,PEmail,OAStreet,OACity,OAState,OACountry,OAZipCode,PAStreet,PACity,PAState,PACountry,PAZipCode);
            //AddEntry.Save();


        }
使用系统;
使用系统数据;
使用系统配置;
使用aspdotnet.DataAccessLayer;
命名空间aspdotnet.BusinessLogicLayer
{
公共类联系人条目
{
私人int_联系人ID;
私有字符串\u标题;
私有字符串_FirstName;
私有字符串\u MiddleName;
私有字符串_LastName;
私有字符串\u作业标题;
私人字符串公司;
私人字符串(string)网站;;
私用电话串;
私人电话;
私有字符串(u Mobile),;
私人字符串传真;
私人字符串(OEmail);;
私人字符串(PEmail),;
私有字符串_OAStreet;
私人字符串(OACity);;
私有字符串_OAState;
私人字符串(OAU国家);;
私有字符串_OAZipCode;
私有字符串\u PAStreet;
私有字符串容量;
私有字符串_PAState;
私有字符串国家;
私有字符串_PAZipCode;
公共int联系人ID
{
获取{return\u ContactID;}
设置{u ContactID=value;}
}
公共字符串标题
{
获取{return\u Title;}
设置{u Title=value;}
}
公共字符串名
{
获取{return\u FirstName;}
设置{u FirstName=value;}
}
公共字符串中间名
{
获取{return\u MiddleName;}
设置{u MiddleName=value;}
}
公共字符串姓氏
{
获取{return\u LastName;}
设置{u LastName=value;}
}
公共字符串职务
{
获取{return\u JobTitle;}
设置{u JobTitle=value;}
}
公共字符串公司
{
获取{return\u Company;}
设置{u Company=value;}
}
公共字符串网站
{
获取{return\u网站;}
设置{u网站=值;}
}
公用电话串
{
获取{return}OfficePhone;}
设置{u OfficePhone=value;}
}
公共字符串家庭电话
{
获取{return\u HomePhone;}
设置{u HomePhone=value;}
}
公共字符串移动
{
获取{return\u Mobile;}
设置{u Mobile=value;}
}
公共字符串传真
{
获取{return\u Fax;}
设置{u Fax=value;}
}
公共字符串电子邮件
{
获取{return\OEmail;}
设置{uoemail=value;}
}
公用电话
{
获取{return\u PEmail;}
设置{u PEmail=value;}
}
公共字符串OAStreet
{
获取{return\u OAStreet;}
设置{u OAStreet=value;}
}
公共城市
{
获取{return\u OACity;}
设置{uOAcity=value;}
}
公共字符串状态
{
获取{return\u OAState;}
设置{u OAState=value;}
}
公共字符串
{
获取{return}
设置{0OACountry=value;}
}
公共字符串OAZipCode
{
获取{return\u OAZipCode;}
设置{u OAZipCode=value;}
}
公共字符串PAStreet
{
获取{return\u PAStreet;}
设置{u PAStreet=value;}
}
公共字符串容量
{
获取{return\u PACity;}
设置{u容量=值;}
}
公共字符串PAState
{
获取{return\u PAState;}
设置{u PAState=value;}
}
公共字符串国家
{
获取{return\u paccountry;}
设置{u paccountry=value;}
}
公共字符串PAZipCode
{
获取{return\u PAZipCode;}
设置{u PAZipCode=value;}
}
公共通讯录()
{
}
公众联络入口(int ContactID、字符串Title、字符串FirstName、字符串MiddleName、字符串LastName、字符串JobTitle、字符串Company、字符串网站、字符串电话、字符串家庭电话、字符串手机、字符串传真、字符串电子邮件、字符串PEmail、字符串OAStreet、字符串OACity、字符串OAState、字符串OACountry、字符串OAZipCode、字符串PAStreet、字符串PACity、string PAState、字符串paccountry、字符串PAZipCode)
{
_ContactID=ContactID;
_头衔=头衔;
_名字=名字;
_中间名=中间名;
_LastName=LastName;
_职位=职位;
_公司=公司;
_网站=网站;
_OfficePhone=OfficePhone;
_家庭电话=家庭电话;
_移动=移动;
_传真=传真;
_OEmail=OEmail;
_派梅尔=派梅尔;
_OAStreet=OAStreet;
_OACity=OACity;
_OAState=OAState;
_OACountry=OACountry;
_OAZipCode=OAZipCode;
_帕斯特里特=帕斯特里特;
_和平=和平;
_PAState=PAState;
_太平洋国家=太平洋国家;
_PAZipCode=PAZipCode;
}
公共bool Save()
{   
如果(_ContactID==0)
返回Insert();
其他的
返回更新();
}
私有布尔插入()
{
_联系人ID=
//...
string PAState = this.txtPAState.Text; 
string PACountry = this.txtPACountry.Text; 
string PAZipCode = this.txtPAZipCode.Text;
string contactIDstr = Session["ContactID"] as string;
int contactID = 0;

if(!String.IsNullOrEmpty(conactIDStr))
    Int32.TryParse(contactIDStr, out contactID);

aspdotnet.BusinessLogicLayer.ContactEntry AddEntry = new ContactEntry(
    contentID,
    Title,
    FirstName,MiddleName,LastName,JobTitle,Company,
    Website,OfficePhone,HomePhone,Mobile,Fax,OEmail,PEmail,
    OAStreet,OACity,OAState,OACountry,OAZipCode,PAStreet,PACity,PAState,PACountry,PAZipCode
); 
ContactEntry cEntry = null;
    if(Session["ContactID"] != null)
    {
        if(!String.IsNullOrEmpty(Session["ContactID"]))
        {
        cEntry = new ContactEntry(Convert.ToInt32(Session["ContactID"].ToString());
        }
    }
Convert.ToInt32(Session["ContactID"].ToString())