sql data source pass a variable, c#,

Posted on 2009-02-22
Last Modified: 2013-12-17
Hi I have the follwoing code

in aspx page

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LiveConnectionString %>"
        SelectCommand="select commentsleftby, comments from ratingsandcomments where Video_ID = @videoid ">
          <asp:parameter name="videoid" defaultvalue ="" />


c# page

protected void _data_Selecting(object sender, SqlDataSourceSelectingEventArgs

        e.Command.Parameters["videoid"].Value = Request.QueryString["Video"].ToString();

what i want to do is get the value from the query string and pass it into the datasource

what am i doing wrong


Question by:R8VI
    1 Comment
    LVL 15

    Accepted Solution

    Set the parameter in the form_load

    SqlDataSource1.SelectParameters["videoid"].DefaultValue = Request.QueryString["video"].ToString()

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now