为什么show.aspx页面不能显示内容?
在default.aspx 页面我是这样写链接代码的:
<a href='Show.aspx?nid=<%#Eval("nclassid")%>&id=<%#Eval("id")%>' ><%# Eval("Title")%></a>
在show.aspx页面放一个组件:
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<TABLE class=line20px1 cellSpacing=0 cellPadding=4
width="100%" border=0>
<TR>
<TD vAlign=top>
<%# DataBinder.Eval(Container.DataItem, "content")%></TD></TR>
</TABLE></ItemTemplate>
</asp:Repeater>
show.aspx.cs的代码如下:
int id = System.Convert.ToInt32(Request.Params["id"]); int nid = System.Convert.ToInt32(Request.Params["nclassid"]); if (!IsPostBack) { my_conn.Open(); OleDbCommand my_comm = new OleDbCommand("select * from info where [color=#FF0000]nclassid=" + nid + " and [/color]id=" + id + "", my_conn);//这一句是不是有问题? Repeater1.DataSource = my_comm.ExecuteReader(); Repeater1.DataBind(); DataSet myDataSet = new DataSet(); }
select * from info where nclassid ='" + nid + "' and id='" + id + "'"
[解决办法]
OleDbCommand my_comm = new OleDbCommand("select * from info where [color=#FF0000]nclassid=@nid and id=@id", my_conn); myCommand.Parameters.Add(new SqlParameter("@nid", SqlDbType.Int)); myCommand.Parameters["@nid"].Value = nid; myCommand.Parameters.Add(new SqlParameter("@id", SqlDbType.Int)); myCommand.Parameters["@id"].Value = id;