还是执行web页面时候出现的错误:
“/Web”应用程序中的服务器错误。未将对象引用设置到对象的实例。说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误: 
行 43:            {
行 44:                Console.Write(e.Message);
行 45:                throw e;
行 46:            }
行 47:        }源文件: D:\HR\HRDAL\ResumeService.cs    行: 45 附ResumeService.cs代码(字数限制,省去一部分用不到的):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HRModels;
using System.Data.SqlClient;namespace HRDAL
{
   public static partial class ResumeService
    {
       //添加简历
       public static Resume AddResume(Resume resume)
       { 
       string sql=
           "INSERT Resume (userId, name, sex, identityNo, birthday, stature, degree, school, marriage, occupation, career, specialty, email, phone, address)"+"VALUES(@userId, @name, @sex, @identityNo, @birthday, @stature, @degree, @school, @marriage, @occupation, @career, @specialty, @email, @phone, @address)";
       sql +="; SELECT @@IDENTITY";
           try
           {
               SqlParameter[] para=new SqlParameter[]
               { 
                   new SqlParameter("@userId",resume.User.UserId),//FK
                   new SqlParameter("@name",resume.Name),
                   new SqlParameter("@sex",resume.Sex),
                   new SqlParameter("@identityNo",resume.IdentityNo),
                   new SqlParameter("@birthdy",resume.Birthday),
                   new SqlParameter("@stature",resume.Stature),
                   new SqlParameter("@degree",resume.Degree),
                   new SqlParameter("@school",resume.School),
                   new SqlParameter("@marriage",resume.Marriage),
                   new SqlParameter("@occupation",resume.Occupation),
                   new SqlParameter("@career",resume.Career),
                   new SqlParameter("@specialty",resume.Specialty),
                   new SqlParameter("@email",resume.Email),
                   new SqlParameter("@phone",resume.Phone),
                   new SqlParameter("@address",resume.Address)
               };
               int newId=DBhelper.GetScalar(sql, para);
               return GetResumeByResumeId(newId);
           }
           catch(Exception e)
           {
               Console.Write(e.Message);
               throw e;
           }
       }
       //修改简历
       public static void ModifyResume(Resume resume)
       {
           string sql =
               "update Resume" +
               "set" +
               "userId=@userId," +//FK
               "name=@name," +
               "sex=@sex," +
               "identityNo=@identityNo," +
               "birthday=@birthday," +
               "stature=@stature," +
               "degree=@degree," +
               "school=@school," +
               "marriage=@marriage," +
               "occupation=@occupation," +
               "career=@career," +
               "specialty=@specialty," +
               "email=@email," +
               "phone=@phone," +
               "address=@address," +
               "where resumeId=@resumeId";
           try
           {
               SqlParameter[] para = new SqlParameter[] 
               {
                   new SqlParameter("@resumeId",resume.ResumeId),
                   new SqlParameter("@userId",resume.User.UserId),//FK
                   new SqlParameter("@name",resume.Name),
                   new SqlParameter("@sex",resume.Sex),
                   new SqlParameter("@identityNo",resume.IdentityNo),
                   new SqlParameter("@birthdy",resume.Birthday),
                   new SqlParameter("@stature",resume.Stature),
                   new SqlParameter("@degree",resume.Degree),
                   new SqlParameter("@school",resume.School),
                   new SqlParameter("@marriage",resume.Marriage),
                   new SqlParameter("@occupation",resume.Occupation),
                   new SqlParameter("@career",resume.Career),
                   new SqlParameter("@specialty",resume.Specialty),
                   new SqlParameter("@email",resume.Email),
                   new SqlParameter("@phone",resume.Phone),
                   new SqlParameter("@address",resume.Address),
               };
               DBhelper.ExecuteCommand(sql,para);
           }
           catch (Exception e)
           {
               Console.WriteLine(e.Message);
               throw e;
           }
       }
       //获取所有简历
       public static IList<Resume> GetAllResumes()
       {
           string sqlAll = "select * from Resume";
           return GetResumeBySql(sqlAll);
       }
       //根据resumeId获取简历
       public static Resume GetResumeByResumeId(int resumeId)
       {
           string sql = "SELECT * FROM Resume WHERE ResumeId=@ResumeId";
           int userId;
           try
           {
               SqlDataReader reader = DBhelper.GetReader(sql, new SqlParameter("@ResumeId", resumeId));
               if (reader.Read())
               {
                   Resume resume = new Resume();
                   resume.ResumeId = (int)reader["resumeId"];
                   resume.Name = (string)reader["name"];
                   resume.Sex = (string)reader["sex"];
                   resume.IdentityNo = (string)reader["identityNo"];
                   resume.Birthday = (DateTime)reader["birthday"];
                   resume.Stature = (string)reader["stature"];
                   resume.Degree = (string)reader["degree"];
                   resume.School = (string)reader["school"];
                   resume.Marriage = (string)reader["marriage"];
                   resume.Occupation = (string)reader["occupation"];
                   resume.Career = (string)reader["career"];
                   resume.Specialty = (string)reader["specialty"];
                   resume.Email = (string)reader["email"];
                   resume.Phone = (string)reader["phone"];
                   resume.Address = (string)reader["address"];
                   userId = (int)reader["userId"];//FK
                   reader.Close();
                   resume.User = UserService.GetUserByUserId(userId);
                   return resume;
               }
               else
               {
                   reader.Close();
                   return null;
               }
           }
           catch (Exception e)
           {
               Console.WriteLine(e.Message);
               throw e;
           }
       }
       //根据userId获取简历
       public static Resume GetResumeByUserId(int userId)
       {
           string sql = "select * from Resume where userId=@UserId";
           try
           {
               SqlDataReader reader = DBhelper.GetReader(sql,new SqlParameter("@userId",userId));
               if (reader.Read())
               { 
                   Resume resume = new Resume();
                   resume.ResumeId = (int)reader["resumeId"];
                   resume.Name = (string)reader["name"];
                   resume.Sex = (string)reader["sex"];
                   resume.IdentityNo = (string)reader["identityNo"];
                   resume.Birthday = (DateTime)reader["birthday"];
                   resume.Stature = (string)reader["stature"];
                   resume.Degree = (string)reader["degree"];
                   resume.School = (string)reader["school"];
                   resume.Marriage = (string)reader["marriage"];
                   resume.Occupation = (string)reader["occupation"];
                   resume.Career = (string)reader["career"];
                   resume.Specialty = (string)reader["specialty"];
                   resume.Email = (string)reader["email"];
                   resume.Phone = (string)reader["phone"];
                   resume.Address = (string)reader["address"];
                   reader.Close();
                   resume.User = UserService.GetUserByUserId(userId);
                   return resume;
               }
               else
               {
                   reader.Close();
                   return null;
               }
           }
           catch (Exception e)
           {
               Console.WriteLine(e.Message);
               throw e;
           }
       }
    }
}
还有一个问题:为什么我的页面用detailsview控件绑定的headertext显示出来的文字都是竖向排列的:




这个方式的呢?设置了headstyle 的width也是无法改变,有什么办法可以让他横向排列吗?
谢谢大家了先,论坛大神很多,受益很多,在此谢谢先前帮我的大神!!!ASP.NETSQL对象Web

解决方案 »

  1.   

    补充一下,问题出现在添加简历的那段代码,public static Resume AddResume(Resume resume)
      

  2.   

    insert 后面不是要跟into么
      

  3.   

    AddResume里面 的"INSERT Resume  缺少 into 
      

  4.   

    貌似不行,我加上INTO也是提示相同的错误!!!
      

  5.   

    空引用错误,调用了null的对象
    这种问题你调一下就知道了,贴一大堆代码上来看不晕么
      

  6.   

    可我调试了,也找不到问题所在!对这个东西刚开始入手,不是很熟练!设置断点后,在读取SqlParameter[] para = new SqlParameter[]
                   { 
                       new SqlParameter("@userId",resume.User.UserId),//FK
                       new SqlParameter("@name",resume.Name),
                       new SqlParameter("@sex",resume.Sex),
                       new SqlParameter("@identityNo",resume.IdentityNo),
                       new SqlParameter("@birthdy",resume.Birthday),
                       new SqlParameter("@stature",resume.Stature),
                       new SqlParameter("@degree",resume.Degree),
                       new SqlParameter("@school",resume.School),
                       new SqlParameter("@marriage",resume.Marriage),
                       new SqlParameter("@occupation",resume.Occupation),
                       new SqlParameter("@career",resume.Career),
                       new SqlParameter("@specialty",resume.Specialty),
                       new SqlParameter("@email",resume.Email),
                       new SqlParameter("@phone",resume.Phone),
                       new SqlParameter("@address",resume.Address)
                   };
    时候出现异常,但我能力有限,还请高人给瞅瞅哪里不对了,这个是照着书本吵的,我实在找不出哪里的问题了!
      

  7.   


    int newId = DBhelper.GetScalar(sql, para);这个一般返回的是object吧但是没有CTE...  友情提示 : 断点 newId 
      

  8.   


    object obj = 5;
    int num = obj;
    这样会CTE的
      

  9.   

    resume
    resume.User
    这两个对象可能为空,检查一下就知道原因了。
      

  10.   

    以前遇到过这样的问题,貌似就是你传过去的这些SqlParameter,如果里面的某一个或多个参数有为空的情况就会报这样的异常,插入断点单步条跟一下
      

  11.   

    SqlParameter传的值可能有空的,对比一下数据库是不是有的字段不能为空
      

  12.   


      //根据resumeId获取简历
           public static Resume GetResumeByResumeId(int resumeId)
           {
               string sql = "SELECT * FROM Resume WHERE ResumeId=@ResumeId";
               int userId;
               try
               {
                   SqlDataReader reader = DBhelper.GetReader(sql, new SqlParameter("@ResumeId", resumeId));
                   if (reader.Read())
                   {
                       Resume resume = new Resume();
                       resume.ResumeId = (int)reader["resumeId"];
                       resume.Name = (string)reader["name"];
                       resume.Sex = (string)reader["sex"];
                       resume.IdentityNo = (string)reader["identityNo"];
                       resume.Birthday = (DateTime)reader["birthday"];
                       resume.Stature = (string)reader["stature"];
                       resume.Degree = (string)reader["degree"];
                       resume.School = (string)reader["school"];
                       resume.Marriage = (string)reader["marriage"];
                       resume.Occupation = (string)reader["occupation"];
                       resume.Career = (string)reader["career"];
                       resume.Specialty = (string)reader["specialty"];
                       resume.Email = (string)reader["email"];
                       resume.Phone = (string)reader["phone"];
                       resume.Address = (string)reader["address"];
                       userId = (int)reader["userId"];//FK  楼主检查下这里是否为null
                       reader.Close();
                       resume.User = UserService.GetUserByUserId(userId);
                       return resume;
                   }
                   else
                   {
                       reader.Close();
                       return null;
                   }
               }
               catch (Exception e)
               {
                   Console.WriteLine(e.Message);
                   throw e;
               }
           }
      

  13.   

    现在调试了结果是这样的:我逐步调试后,在UserService.cs中添加简历
    方法中 new SqlParameter("@userId",company.User.UserId),//FK
    这个地方显示,值为空!我在前台页面中数据源如何修改呢?这是前台插入代码的参数(就是利用gridview控件插入一个个人简历信息中,插入方法的参数):
    <InsertParameters>
                    <asp:SessionParameter SessionField="userId" DefaultValue="userId" Name="userId" Type="Int32" />
                    <asp:Parameter Name="name" Type="String" />
                    <asp:Parameter Name="sex" Type="String" />
                    <asp:Parameter Name="identityNo" Type="String" />
                    <asp:Parameter Name="birthday" Type="DateTime" />
                    <asp:Parameter Name="stature" Type="String" />
                    <asp:Parameter Name="degree" Type="String" />
                    <asp:Parameter Name="school" Type="String" />
                    <asp:Parameter Name="marriage" Type="String" />
                    <asp:Parameter Name="occupation" Type="String" />
                    <asp:Parameter Name="career" Type="String" />
                    <asp:Parameter Name="specialty" Type="String" />
                    <asp:Parameter Name="email" Type="String" />
                    <asp:Parameter Name="phone" Type="String" />
                    <asp:Parameter Name="address" Type="String" />
                </InsertParameters>
    现在调试后出现System.FormatException: 输入字符串的格式不正确。
    书本上的代码是没有 <asp:SessionParameter SessionField="userId" DefaultValue="userId" Name="userId" Type="Int32" />的,但是没有的话,会报错说ObjectDataSource"odsResume"未能找到带参数的非泛型方法"AddResume": Name, Sex, IdentityNo, Birthday, Stature, Degree!
    真不知道如何修改了,哪位能帮我看一下!谢谢了!或者加我Q568039554,我发送代码给您看一下!