protected void show_lib()
  {
  string cid = Request.QueryString["cid"];
  string strconn = ConfigurationSettings.AppSettings["strconn"];
  SqlConnection conn = new SqlConnection(strconn);
  string strsql = "select * from View_lib_report where Cid='" + cid + "' and Sid='" + Session["stuID"] + "'";
  SqlCommand cmd = new SqlCommand(strsql, conn);
  try
  {
  conn.Open();
  SqlDataReader sda = cmd.ExecuteReader();
  while (sda.Read())
  {
  this.lbname.Text = sda.GetValue(1).ToString();
  this.lbmajor.Text = sda.GetValue(3).ToString();
  this.lbgrade.Text = sda.GetValue(2).ToString();
  this.lbClass.Text = sda.GetValue(4).ToString();
  this.ddlTitle.Items.Add(sda.GetValue(6).ToString());
  this.ddlTeacher.Items.Add(sda.GetValue(7).ToString());
  this.TextArea1.Value = sda.GetValue(8).ToString();
  this.Textarea2.Value = sda.GetValue(9).ToString();
    
  }
  }
  catch
  {
  return;
  }
  finally
  {
  cmd.Dispose();
  conn.Close();
  }
  }

解决方案 »

  1.   

    使用request["cid"]
    1.Request.Form:获取以POST方式提交的数据(接收Form提交来的数据);   2.Request.QueryString:获取地址栏参数(以及以GET方式提交的数据)   3.Request:包含以上两种方式(优先获取GET方式提交的数据),它会在QueryString、Form、ServerVariable中都搜寻一遍。   而且有时候也会得到不同的结果。如果你仅仅是需要Form中的一个数据,但是你使用了Request而不是Request.Form,那么程序将在QueryString、ServerVariable中也搜寻一遍。如果正好你的QueryString或者ServerVariable里面也有同名的项,你得到的就不是你原本想要的值了。要养成习惯,最起码为了网页的完整,你也得加上NULL处理呀。呵呵if(cid==null)
    {}
    else
    {}
      

  2.   

    如果你传过来是null的,无论怎样都不妥啊,应该考虑的是为什么传过来是null了,....aspx?cid="2" ,这种形式写对了没
    。做非空值判断也只能给cid一个默认值而已
      

  3.   

    你这个CID可以传过来值,你先把Try{}catch{}这个去掉,你看错误到底出现在哪,或者是,你先一步一步的来测试,先检测是否收到CID的值,然后再查询表什么的。
        protected void Page_Load(object sender, EventArgs e)
        {
            string cid = Request.QueryString["cid"];
            Response.Write(cid);
        }