2013-02-05 44 views
1

我試圖從源代碼傳遞查詢中的Request.QueryString整型值。我該怎麼做?從源代碼傳遞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]** "> 

回答

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

完美!謝謝! – Arbaaz

0

您可以使用此:

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