我想在 SQLDataSource 中创建一个动态选择命令。它应该从使用 get 发送的 URL 中读取一个值,抓取它并将其粘贴到 select 命令中。
我的sqldatadource在我的aspx页面中,看起来像这样
<asp:SqlDataSource ID="DS" Runat="server"
SelectCommand="SELECT * FROM [dbo].[DS] WHERE [Install Process] = 'OCC'
AND [The Date] = @theDate"
ConnectionString="<%$ ConnectionStrings:ApplicationServices %>">
</asp:SqlDataSource>
我想更新日期参数。我猜你不能在Page_Load更新它,因为页面还没有加载,但老实说我不确定。我可以从 sqldatasource 中调用代码隐藏函数或其他东西吗?
这是我的代码隐藏。它目前处于page_load方法中,但我猜我需要移动它?任何帮助都会很棒。谢谢
protected void Page_Load(object sender, EventArgs e)
{
string theDate = Request.QueryString["TheDate"];
DS.SelectParameters.Add("@theDate", theDate);
DS.SelectParameters["theDate"].DefaultValue = theDate.ToString();
}
您不能在 SqlDataSource 的 aspx 声明中使用 SelectParameters 集合的 QueryStringParmater,如此处所述?
这是我使用过的最好的示例之一,请在页面中以编程方式检查分配参数值。
http://www.asp.net/web-forms/tutorials/data-access/accessing-the-database-directly-from-an-aspnet-page/using-parameterized-queries-with-the-sqldatasource-cs