Question

I'm using an SqlDataSource and gridview to display some data, the data being displayed related to the url parameter. So in my case, my url paramter is ?orderid={number} and I want to use that for my query. I've been fiddling about but cant seem to get anywhere with it.

Here is my code;

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

    ConnectionStrings:ConnectionString %>" SelectCommand="
        SELECT f.filmID, f.filmTitle, f.filmPrice 
        FROM films f 
        INNER JOIN orderItems o 
        ON f.filmID = o.filmID 
        WHERE (o.orderID = @orderID)">
        <SelectParameters>
            <asp:QueryStringParameter Name="orderID" QueryStringField="orderid" />
        </SelectParameters>

</asp:SqlDataSource>
Was it helpful?

Solution

This looks correct. If it is not working, I would try adding a DbType, DefaultValue and/or ConvertEmptyStringToNull paramenter.

DbType –The Data Type of the SQL Parameter DefaultValue (Optional) – Here you can specify the Default Value of the Parameter when the QueryString Parameter is missing or not supplied. ConvertEmptyStringToNull (Optional) – As the Name suggests this will set the Parameter value to NULL when it is empty or blank.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top