string message = string.Empty;
            int result = 0;
            entity = new OutpadmRegister();
            entity.RegisterID = registerID;
       
            entity.medicalID = medicalID;
            entity.CardID = cardID;
            entity.GroupID = groupID;
            entity.DiagnosisDate = DateTime.Now.Date;
            entity.InputTime = DateTime.Now;
            entity.DoctorID = doctorID;
            entity.State = (int)EnumDataState.Start;
            entity.RegisterQuarryState = (int)EnumRegisterRoot.Normal;
            entity.DiagnosisState = (int)EnumCureState.Insert;
            entity.DiagnosisRoot = 2;
            entity.IsFirst = 1;
            entity.IsAdd = 1;
            entity.IsCure = 0;
            entity.IsEmergency = 0;
            entity.IsEspecially = 0;
            entity.State = 1;          
           // 临时患者建档
            if (name != string.Empty)
            {
                pat = new PATPatient();
                pat.PatientID = patientID;
                entity.PatientID =pat.PatientID;
                pat.PatientTypeID = "XJ01";
                pat.BirthDay = DateTime.Parse(birthDay);
                entity.BirthDay = pat.BirthDay;
                pat.Name = name;
                entity.Name =pat.Name;
                pat.SexID = sexID;
                entity.SexID = pat.SexID;
                pat.CardCode = cardID;
                entity.CardID = pat.CardCode;
                pat.State = (int)EnumDataState.Start;
                pat.VisitState = 0;
                pat.FirstTime = DateTime.Now;
                pat.LastTime = DateTime.Now;
               
                //DBHelper.Insert<PATPatient>(pat);
                
            }
           
            try { if (entity != null) { result = DBHelper.Insert<OutpadmRegister>(entity); } }
            catch (Exception ex) { ex.ToString(); }这个是源码每次执行到result = DBHelper.Insert<OutpadmRegister>(entity);这句就会引发该异常,以检查过entity并非空值。数目与数据库中非空字段数目一至。还请各位高手指点一下

解决方案 »

  1.   

    DBHelper  实例化了吗?
      

  2.   

    result = DBHelper.Insert<OutpadmRegister>(entity);Debug一下Insert方法里面,是否有没有实例化的对象.  应该是Insert方法里面抛出的异常.
      

  3.   

    忘了回帖,问题以解决,是连接数据库的字符串没有获取到值。╮(╯▽╰)╭,粗心是一种罪过。
     private static Gateway CreateGateway()
            {
                try
                {
                    string[] str = Base.Split(System.Configuration.ConfigurationManager.AppSettings["Sql"],"|");
                    DbProvider dp = new NBear.Data.SqlServer.SqlDbProvider(String.Format("Server={0};Database={1};Uid={2};Pwd={3}", str[0], str[1], str[2], str[3]));
                    Database db = new Database(dp);
                    return tGateway = new Gateway(db);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }