public string ShowSubject, ShowTime, ShowContent, ShowName;
    protected void Page_Load(object sender, EventArgs e)
    {
        string cmdtxt = "select * from tb_LeaveWord where ID='" + Request["ID"].ToString() + "'";//错误在这
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
        con.Open();
        SqlCommand com = new SqlCommand(cmdtxt, con);
        SqlDataReader dr = com.ExecuteReader();
        dr.Read();
        if (dr.HasRows)
        {
            ShowSubject = dr["Subject"].ToString();
            ShowTime = dr["DataTime"].ToString();
            ShowContent = dr["Content"].ToString();
            ShowName = dr["Uid"].ToString();
        }
        dr.Close();
        this.dlBind();
    }

解决方案 »

  1.   

    request["ID"]为null,不能tostring()
      

  2.   

    在这一行前加一个判断,判断Request["ID"]是否为null
       string cmdtxt = "select * from tb_LeaveWord where ID='" + Request["ID"].ToString() + "'";//错误在这 
      

  3.   

            string cmdtxt = "select * from tb_LeaveWord where ID='" + Request["ID"] + "'";//错误在这 
      

  4.   

    public string ShowSubject, ShowTime, ShowContent, ShowName; 
        protected void Page_Load(object sender, EventArgs e) 
        { try{
               string a =Request["ID"].ToString();
             }
           catch{
            string cmdtxt = "select * from tb_LeaveWord where ID='" + Request["ID"].ToString() + "'";//错误在这 
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]); 
            con.Open(); 
            SqlCommand com = new SqlCommand(cmdtxt, con); 
            SqlDataReader dr = com.ExecuteReader(); 
            dr.Read(); 
            if (dr.HasRows) 
            { 
                ShowSubject = dr["Subject"].ToString(); 
                ShowTime = dr["DataTime"].ToString(); 
                ShowContent = dr["Content"].ToString(); 
                ShowName = dr["Uid"].ToString(); 
            } 
            dr.Close(); 
            this.dlBind(); 
        }
    }
      

  5.   

    public string ShowSubject, ShowTime, ShowContent, ShowName; 
       sting x=null;
        protected void Page_Load(object sender, EventArgs e) 
        { try{ 
              string a =Request["ID"].ToString(); 
               x=a;
            } 
          catch{ 
            string cmdtxt = "select * from tb_LeaveWord where ID='" + Request["ID"].ToString() + "'";//错误在这 
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]); 
            con.Open(); 
            SqlCommand com = new SqlCommand(cmdtxt, con); 
            SqlDataReader dr = com.ExecuteReader(); 
            dr.Read(); 
            if (dr.HasRows) 
            { 
                ShowSubject = dr["Subject"].ToString(); 
                ShowTime = dr["DataTime"].ToString(); 
                ShowContent = dr["Content"].ToString(); 
                ShowName = dr["Uid"].ToString(); 
            } 
            dr.Close(); 
            this.dlBind(); 
        } 

    上面的那个错了
      

  6.   

    Request["ID"] 的值为空,当你对Request["ID"]做ToString()做转化时候自然就会报那个错误
      

  7.   

    Request["ID"]一定要注意"ID"是 name="ID" 不是ID="ID"比如:<input name="ID"> 使用Request["ID"]可以获取到.而<input id="ID"> 使用Request["ID"]是获取不到的.
      

  8.   

    Request["ID"]为空,你再ToString()肯定会报错撒
      

  9.   

    asp。net学习中。request["ID"].toString()这个里面的值 因该是为空的 
      

  10.   

    楼主你的Request["ID"]等于null,所以出现了现在你的问题
      

  11.   

    错误,楼上都已说了。 Request["ID"].ToString() 所有参数在sql语句中,最好事先处理一下各种情况,