gpt4 book ai didi

c# - 如何在 SelectCommand Asp.net 中设置传递变量

转载 作者:太空宇宙 更新时间:2023-11-03 13:12:13 24 4
gpt4 key购买 nike

我试过这个例子,但没有用。

<%string id = Request.QueryString["id"]; %>// get value and set in one variable
<%=id%>// display successfully variable's value
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [id], [name], [image], [old_price], [new_price] FROM [product] where [id]= "'<%=id%>'"" ></asp:SqlDataSource>

SelectCommand 中的一个问题如何在查询中设置变量我尝试像 <%=id%>

最佳答案

使用代码隐藏,例如 Selecting event :

<asp:SqlDataSource ID="SqlDataSource1" ... OnSelecting="Product_Selecting">

代码隐藏:

protected void Product_Selecting(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters[0].Value = Request.QueryString["id"];
}

关于c# - 如何在 SelectCommand Asp.net 中设置传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28026311/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com