【问题标题】:SqlDataSource Connection sting + Textbox valueSqlDataSource 连接字符串 + 文本框值
【发布时间】:2014-03-10 18:34:18
【问题描述】:

您好,感谢您的阅读。

我有一个与我的 asp:repeater 一起使用的 SqlDataSource。

<asp:SqlDataSource runat="server" ID="SqlDataSource" ConnectionString='<%$ ConnectionStrings:Support_SystemConnectionString %>' SelectCommand="SELECT * FROM [Comment]"></asp:SqlDataSource>

我的问题是:如何让它从我的表注释中选择 TicketID,它等于我的文本框“DetailedID”中的值?

<asp:TextBox runat="server" ID="DetailedID" PlaceHolder="ID" ReadOnly="true" />

我认为我的 SelectCommand 应该是这样的:SelectCommand="SELECT * FROM [Comment] Where ([TicketID] =DetailedID)"

感谢您的阅读,希望您能帮到我。

【问题讨论】:

    标签: html asp.net sql


    【解决方案1】:

    您可以为选择查询指定ControlParameter。查询也应更新以使用此参数:

    <asp:SqlDataSource runat="server" ID="SqlDataSource"
                       ConnectionString='<%$ ConnectionStrings:Support_SystemConnectionString %>'
                       SelectCommand="SELECT * FROM [Comment] Where (@DetailedID IS NULL OR [TicketID] = @DetailedID)">
        <SelectParameters>
            <ControlParameter ControlID="DetailedID" PropertyName="Text" Name="DetailedID" />
        </SelectParameters>
    </asp:SqlDataSource>
    

    【讨论】:

    • 什么是控制参数?
    猜你喜欢
    • 1970-01-01
    • 2010-11-27
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多