我试图在源代码的查询中传递Request.QueryString整数值。我该怎么做?

http://localhost:3738/WebSite3/UserDetails.aspx?Id=43


我想在查询中传递id的值即43

 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:SLIITComDBConnectionString %>"

    SelectCommand="SELECT Album.AlbumID, Album.DefaultPhotID, Album.AlbumName, PhotAlbum.Photo FROM Album INNER JOIN PhotAlbum ON Album.DefaultPhotID = PhotAlbum.PhotoID where album.userid= **Request.QueryString[id]** ">

最佳答案

使用QueryStringParameter

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:SLIITComDBConnectionString %>"

SelectCommand="SELECT Album.AlbumID, Album.DefaultPhotID, Album.AlbumName, PhotAlbum.Photo FROM Album INNER JOIN PhotAlbum ON Album.DefaultPhotID = PhotAlbum.PhotoID where album.userid= @userid ">
   <SelectParameters>
      <asp:QueryStringParameter Name="userid" Type="String"  QueryStringField="id" />
   </SelectParameters>
</asp:SqlDataSource>

关于c# - 从源代码在SQL查询中传递Request.QueryString整数值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14706672/

10-16 08:59