将Guid传递给Asp.Net中的SQL代码

时间:2017-10-17 11:57:15

标签: sql asp.net

这个SQL代码在Asp.Net代码本身中,那么如何将WHERE设置为等于我在requestQuery String中传递的Guid? 例如,我想提出类似WHERE tblEntrants.compID = Request.QueryString("Comp")的内容,但显然我无法做到。 QueryString中的Guid需要以某种方式传入此SQL查询。我对这一切都很陌生,所以如果有人能提供帮助,我会非常感激。

<asp:SqlDataSource ID="DSEntrants" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" SelectCommand="SELECT tblEntrants.accountID, tblEntrants.compID, tblaccounts.accountID, tblaccounts.contactName, tblEntrants.paid
        FROM tblAccounts INNER JOIN
            tblEntrants ON tblAccounts.accountID = tblEntrants.accountID  
        WHERE tblEntrants.compID =  ?????????????????
        ORDER BY tblEntrants.accountID DESC"></asp:SqlDataSource>

1 个答案:

答案 0 :(得分:0)

我刚刚弄清楚如何做到这一点。您可以直接设置这样的查询字符串参数..

        <asp:SqlDataSource ID="DSEntrants" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" SelectCommand="SELECT tblEntrants.accountID, tblEntrants.compID, tblaccounts.accountID, tblaccounts.contactName, tblaccounts.skypeUserName, tblEntrants.paid
        FROM tblAccounts INNER JOIN
        tblEntrants ON tblAccounts.accountID = tblEntrants.accountID  
        WHERE tblEntrants.compID = @Event_ID
        ORDER BY tblEntrants.accountID DESC">

        <SelectParameters>
            <asp:QueryStringParameter QueryStringField="compID" Name="Event_ID" />
        </SelectParameters>

一切正常,感谢阅读。