后台:protected void btnDiaoAll_Click(object sender, EventArgs e)
        {
            string id = hf.Value;
            string oper = Request.Cookies["ckuser"].ToString();//就这里出错            if (BaojianAspNet.BLL.MaterialAssignBLL.ExecuteNonQuery(id, DateTime.Now.ToLocalTime(),oper) >= 0)
                ClientScript.RegisterStartupScript(this.GetType(), "", "alert('调派成功!');", true);
            else
                ClientScript.RegisterStartupScript(this.GetType(), "", "alert('调派失败!');", true);           
        }    底层DAL:public static int ExecuteNonQuery(string id, DateTime time, string oper)
        {
            string sql = "update MaterialAssign set State = '1',FinishDat= @date,oper=@oper where pk in(" + id + ")";
            SqlParameter[] para ={ 
                new SqlParameter("@date", time), 
                new SqlParameter("@oper", oper) 
            };
            return SqlHelper.ExecuteNonQuery("", CommandType.Text, sql, para);
        }
    不知道为什么错了~~~~

解决方案 »

  1.   


    if (!string.IsNullOrEmpty(Request.Cookies["ckuser"]))
                {
                    string oper = Request.Cookies["ckuser"].ToString();
                }
      

  2.   

    顺便检查下你给Cookies["ckuser"]赋值时有没有得到数据!
      

  3.   

    if (!string.IsNullOrEmpty(Request.Cookies["ckuser"]))
                {
                    string oper = Request.Cookies["ckuser"].ToString();
                }
    先判断 coolies是否存在,不然request对象去哪找这个ckuser这个参数呢
      

  4.   

    很明显
    你的cookie值就没有获取到啊。 if (Request.Cookies["ckuser"] != null)
                {
    string oper = Request.Cookies["ckuser"].ToString();}
      

  5.   

       是不是出错是因为没有找到COOKIES的值呢?