“/student/StudentManager”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 47: 
行 48:             ///判断用户是否合法
行 49:             if (recu.Read())
行 50:             {
行 51:                 userId = recu["UserID"].ToString();
 源文件: c:\Inetpub\wwwroot\stu\StudentManager\Default.aspx.cs    行: 49 堆栈跟踪: 
[NullReferenceException: 未将对象引用设置到对象的实例。]
   Default.LoginBtn_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\stu\StudentManager\Default.aspx.cs:49
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102 
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42

解决方案 »

  1.   

    if (recu.Read())
    行 50:             {
    行 51:                 if(recu["UserID"]!=null)
    行 52:                   userId = recu["UserID"].ToString();
      

  2.   

    如果是UserID是用户ID,应该不会是null值,可能是recu没有实例,如果经过上面的修改错误仍在,可以再试试“SqlCommand myComm = new SqlCommand(SQL语句,连接语句);
    SqlDataReader recu = SqlCommand.ExecuteReader();//重新实例
    if(recu.Read())
    {
     userId = recu["UserID"].ToString();
    }