我用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();
}
// 在此处放置用户代码以初始化页面
}不知道哪里出错了,请各位大侠指教,谢谢谢谢!
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();
}
// 在此处放置用户代码以初始化页面
}不知道哪里出错了,请各位大侠指教,谢谢谢谢!
解决方案 »
- 用js动态 改变菜单按钮的效果
- 怎么也搞不定这个面试题,有没有高人指点一下...如果你能搞定,我想你的月薪上W没问题...你来试试吧,兄弟们
- 我的asp.net网站放到虚拟主机上不能运行
- TREEVIEW 展开下级节点。
- 请问 如何 快度 清空 datagrid 中的数据?????????????????????
- 请问如果让虚拟目录不应用上级目录的Web.Config?
- 求一个非常简单的发邮件代码
- 怎么在代码里设置checkbox的check属性为true?
- 怎么附值,谢谢(c#)
- 新手问题!如何在ASP.net程序里实现messagebox功能.(C#)
- 分不多
- 有关登录控件中的ChangePassword控件的问题?
SqlCommand cmd=new SqlCommand("select articleContent from
ArticleTB where articleID= '"+ID+" ',con");
--->为SqlCommand cmd=new SqlCommand("select articleContent from
ArticleTB where articleID= '"+ID+" '",con);
如何解决呢??谢谢!
所以出现了错误,传出来的是“ID=1”,而articleID 是int类型的。该怎么办?
SqlCommand cmd=new SqlCommand("select articleContent from
ArticleTB where articleID= "+ID+" ,con); 难道,LZ你没注意varchar和int的区别吗
SqlCommand cmd=new SqlCommand("select articleContent from
ArticleTB where articleID= "+ID+" ,con); 难道,LZ你没注意varchar和int的区别吗
ArticleTB where articleID="+ID ,con);
SqlCommand cmd=new SqlCommand("select articleContent from
ArticleTB where articleID="+ID ,con);
应该是没问题的建议使用参数~~
是不是我哪里出错了呢??在超级链接列的URL字符串中的代码是这样的:showArticle.aspx ? articleID={0},
大家帮忙看看吧!谢谢谢谢!