将 GUID 传递给 SQL 代码 Asp.Net



这个SQL代码在 Asp.Net 代码本身中,那么我怎样才能将WHERE设置为等于我在requestQuery字符串中传递的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>

我刚刚弄清楚了如何做到这一点。你可以像这样直接设置一个查询字符串参数。

        <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>

一切正常,感谢您的阅读。

最新更新