0

I want to create a dynamic select command in an SQLDataSource. It should read a value from the URL sent using get, grab it and stick it into the select command.

My sqldatadource is in my aspx page and looks like this

<asp:SqlDataSource ID="DS" Runat="server"

    SelectCommand="SELECT * FROM [dbo].[DS] WHERE [Install Process] = 'OCC' 
    AND [The Date] = @theDate"

    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>">

</asp:SqlDataSource>

I want to update theDate parameter. I'm guessing you cant update it in Page_Load because the page hasn't loaded yet but I'm honestly not sure. can i call a codebehind function from within the sqldatasource or something...

This is my codebehind. It's currently in the page_load method, but i'm guessing that I need to move it? any help would be great. Thanks

protected void Page_Load(object sender, EventArgs e)
{
    string theDate = Request.QueryString["TheDate"];

    DS.SelectParameters.Add("@theDate", theDate);
    DS.SelectParameters["theDate"].DefaultValue = theDate.ToString();
}

2 Answers 2

0

Can you not use the QueryStringParmater of the SelectParameters collection in the aspx declaration of the SqlDataSource as documented here?

0

This is one of the best samples I have used, check Assigning Parameter Values Programmatically in the page.

http://www.asp.net/web-forms/tutorials/data-access/accessing-the-database-directly-from-an-aspnet-page/using-parameterized-queries-with-the-sqldatasource-cs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.