locked
Request QueryString, Stored Procedure parameters coupled together RRS feed

  • Question

  • User1048318187 posted

    I need to send a querystring object of type string to another page in my site, with sqldatasource object and the querystring value being the input parameter to my stored procedure:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"

        ConnectionString="<%$ ConnectionStrings:mystring %>" SelectCommand="getlatest"

        SelectCommandType="StoredProcedure">

    <SelectParameters>

    <asp:QueryStringParameter  Name="catreg" QueryStringField="catreg" />

    </SelectParameters>

    </asp:SqlDataSource>

    </asp:SqlDataSource>

    SELECT n.idnews,n.title,n.date,n.comments,n.commentcheck,n.idcategory FROM News as N inner join Categories c on c.idcategory = n.idcategory where  c.idcategory in (select c.idcategory from categories where c.catab = @catreg)  ORDER BY date DESC

    ...but not getting any display results as all, even tho I have done a display test for the UR querystring object, knowing it is good and reaching the destination page.

    ???
    TIA
    chumley

    Tuesday, November 26, 2013 7:37 PM

Answers

  • User1508394307 posted

    You can simply check by replacing 

    <asp:QueryStringParameter  Name="catreg" QueryStringField="catreg" />

    with 

    <asp:Parameter Name="catreg" Type="string" DefaultValue="XXX" />

    where XXX is your test value. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 28, 2013 4:02 PM

All replies

  • User697462465 posted

    Hi Chumley,

    According to your description, you are having difficult with pass parameter to stored procedure using sqldatasource control.

    Based on your code, I guess you have forgot to declare the @catreg in procedure.

    Try to change your code as below:

    create procedure usp_procedureName
      @catreg nvarchar
    as
    SELECT n.idnews,n.title,n.date,n.comments,n.commentcheck,n.idcategory FROM News as N inner join Categories c on c.idcategory = n.idcategory where  c.idcategory in (select c.idcategory from categories where c.catab = @catreg)  ORDER BY date DESC
    return 0

    Hope it can help you.

    Best Regards,
    Terry Guo

    Thursday, November 28, 2013 12:30 AM
  • User1048318187 posted

    The parameter was declared (@catreg varchar) in the stored procedure before I docked it. something in the querystringparameter Name or querystringfield seems not to be getting the correct value, or is there another selectparameter or attribute I'm overlooking ???

    Thursday, November 28, 2013 2:18 PM
  • User1508394307 posted

    You can simply check by replacing 

    <asp:QueryStringParameter  Name="catreg" QueryStringField="catreg" />

    with 

    <asp:Parameter Name="catreg" Type="string" DefaultValue="XXX" />

    where XXX is your test value. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 28, 2013 4:02 PM