我正在做一个电影评论网站。ShowMovie.aspx?Id= 6
我无法从 .aspx 页面中的 url 获取 Id
<table border="1" cellpadding="1" cellspacing="1" style="width: 500px;">
<tbody>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblType" runat="server" Text='<%# Eval("Comment") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID='SqlDataSource1' runat='server' ConnectionString='<%$ ConnectionStrings:con %>'
SelectCommand='SELECT [Comment] FROM [Comment] where [MovieId]=<%= Request.QueryString("Id") %>'>
</asp:SqlDataSource>
</tbody>
</table>
但我可以在 .aspx.cs 页面中使用
protected void Page_Load(object sender, EventArgs e) {
Id = Request.QueryString["Id"];
String types = "";
con = new Connect().Connection();
cmd = new SqlCommand("Select * from Movie where Id=" + Id, con);
dr = cmd.ExecuteReader();
dr.Read();
lblTitle.Text = dr["Title"].ToString();
lblDescription.Text = dr["Description"].ToString();
Picture.ImageUrl = dr["Picture"].ToString();
dr.Close();
}
这是“<”附近的错误语法错误。异常详细信息:System.Data.SqlClient.SqlException:“<”附近的语法不正确。
堆栈跟踪:[SqlException (0x80131904):'<' 附近的语法不正确。]