我用DataGrid的超级链接列用Get的方法传值,能打印出值来,但就是不能现实出数据库里面其他的内容,不知道哪里出错了,系统的出错提示是:“ExecuteReader: Connection 属性尚未初始化。” 以下是我的代码:
private void Page_Load(object sender, System.EventArgs e)
{   
if(!this.IsPostBack)
   {   string ID=Request.QueryString.ToString();
                      //this.Response.Write(ID);可以打印;
SqlConnection con=db.createConnection();
con.Open();
SqlCommand cmd=new SqlCommand("select articleContent from 
                        ArticleTB where articleID='"+ID+"',con");
SqlDataReader sdr=cmd.ExecuteReader();
this.DataList1.DataSource=sdr;
this.DataList1.DataBind();
con.Close();
   }
// 在此处放置用户代码以初始化页面
}不知道哪里出错了,请各位大侠指教,谢谢谢谢!

解决方案 »

  1.   


    SqlCommand cmd=new SqlCommand("select articleContent from  
                            ArticleTB where articleID= '"+ID+" ',con"); 
    --->为SqlCommand cmd=new SqlCommand("select articleContent from  
                            ArticleTB where articleID= '"+ID+" '",con); 
      

  2.   

    谢谢,换了之后出现了这个新的错误:“将 varchar 值 'ID=1' 转换为数据类型为 int 的列时发生语法错误。”
    如何解决呢??谢谢! 
      

  3.   

    为什么我打印出来的时候是“ID=1”,而不是直接把主键的值“1”打印出来呢??
    所以出现了错误,传出来的是“ID=1”,而articleID 是int类型的。该怎么办?
      

  4.   

    既然ID是int的,那就
    SqlCommand cmd=new SqlCommand("select articleContent from   
                            ArticleTB where articleID=  "+ID+" ,con); 难道,LZ你没注意varchar和int的区别吗
      

  5.   

    既然ID是int的,那就
    SqlCommand cmd=new SqlCommand("select articleContent from   
                            ArticleTB where articleID=  "+ID+" ,con); 难道,LZ你没注意varchar和int的区别吗
      

  6.   

    还是不行,问题好像是我打印出来的是字符串“ID=1”,不是int类型的主键值,就是不知道该怎么转换,或许是哪里出错了,真烦!
      

  7.   

    SqlCommand cmd=new SqlCommand("select articleContent from    
                            ArticleTB where articleID="+ID ,con);  
      

  8.   

    id如果是Int型的:
    SqlCommand cmd=new SqlCommand("select articleContent from     
                            ArticleTB where articleID="+ID ,con); 
    应该是没问题的建议使用参数~~
      

  9.   

    最令我费解的是代码是一样的为什么我打印出来的是“ID=1”,而人家打印出来的却只是主键值“1”呢??
    是不是我哪里出错了呢??在超级链接列的URL字符串中的代码是这样的:showArticle.aspx ? articleID={0},
    大家帮忙看看吧!谢谢谢谢!
      

  10.   

    string ID=Request.QueryString.ToString(); ----------------------------------------改为下面。string ID=Request.QueryString["articleID"]楼主太外行了吧。