从源代码传递sql查询中的Request.QueryString整数值

时间:2013-02-05 11:39:20

标签: c# asp.net sql

我试图在源代码的查询中传递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]** ">

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:0)

您可以使用:

 <%=this.Request.QueryString["Id"]%>