“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 237:            SqlDataReader dr = sql.ExecuteReader(" SELECT crdate,id,pid,cid,vouchs,name,intro FROM infosort WHERE id=" + PRIMARYKEY);
行 238:
行 239: while(dr.Read())
行 240: {
行 241: infosort.crdate = (DateTime)dr["crdate"];
 源文件: e:\website\App_Code\DALFactory\infosort.cs    行: 239 堆栈跟踪: 
[NullReferenceException: 未将对象引用设置到对象的实例。]
   infosortDAL.Getinfosort(Int32 PRIMARYKEY) in e:\website\App_Code\DALFactory\infosort.cs:239
   infouc.InfoBind() in e:\website\controls\info.ascx.cs:33
   infouc.Page_Load(Object sender, EventArgs e) in e:\website\controls\info.ascx.cs:24
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Control.LoadRecursive() +131
   System.Web.UI.Control.LoadRecursive() +131
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436 
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.1433; ASP.NET 版本:2.0.50727.1433 

解决方案 »

  1.   

    使用DataSet可以解决这个问题。DataReader是保持连接的。所以多人同时的话就会出现问题。
      

  2.   

    while(dr.Read())
    使用后有个关闭if (sdr != null){
    sdr.Close();
    sdr = null;
    }
      

  3.   

    dr["crdate"]有可能为null,
    先判断再转换成DateTime
      

  4.   

    dr["crdate"]肯定有值,默认是getdate(),否则取当前时间
      

  5.   

    注意检查一下是什么情况下出错,调试的时候是不是也会出现这种错误?是否用到session?infosort是不是null
      

  6.   

    调试的时候也是有时错,有时对,没用到session,infosort也不是空