日期:2014-05-20  浏览次数:20816 次

报错 object reference not set to an instance of an object,是什么原因啊
class Customer
    {
......
        public bool save()
        {
            if (this.Id == -1)
            {
                int customerId = DataManager.addCustomer(this);//此处报错
                if (customerId == -1) return false;
                else
                {
                    this.Id = customerId;
                    return true;
                }
            }
            else
            {
                DataManager.UpdataCustomer(this);
                return true;
            }
        }
    }

static class DataManager
{
static public int addCustomer(Customer customer)
        {
            if (getCustomerId(customer.Name)!=-1) return -1;
            tb_Customer tb_customer = new tb_Customer();
            tb_customer.Id = customer.Id;
            tb_customer.Name = customer.Name;
            tb_customer.Password = customer.Password;
            tb_customer.PhoneNumber = customer.PhoneNumber;
            dataContext.tb_Customer.InsertOnSubmit(tb_customer);
            return getCustomerId(customer.Name);
        }
}
------解决方案--------------------
对象未实例化,不能是this,new一个