locked
string in selectcommand? RRS feed

  • Question

  • User1986916315 posted

    I'm trying to setup my SelectCommand in my codebehind to use a WHERE statement that is set by a string (which is set by a dropdownmenu).

     

            string yr = DropDownList1.SelectedValue.ToString();

            SqlDataSource1.SelectCommand = "SELECT Date, Title, Body, Car, ID FROM Schedule WHERE Year(Date) = 'yr' ORDER BY Date DESC";

    Is it possible to do this in my SelectCommand? If so, what do I need to change to get the string to showup in my SelectCommand, where I currently have 'yr' ?

    Monday, February 21, 2011 1:05 AM

Answers

  • User-1373473781 posted

    "SELECT Date, Title, Body, Car, ID FROM Schedule WHERE Year(Date) = '"+yr+"' ORDER BY Date DESC";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 21, 2011 1:16 AM
  • User-1412735316 posted

    You may also check the date fromat of ddl with db.

    Which event are you using to change selectcommand of sqldatasource it's very important. you need to do that before firing selecting event of sqldatasource or within that event. After that no changes in selectcommand will take effect.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 21, 2011 2:24 AM

All replies

  • User-1373473781 posted

    "SELECT Date, Title, Body, Car, ID FROM Schedule WHERE Year(Date) = '"+yr+"' ORDER BY Date DESC";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 21, 2011 1:16 AM
  • User-1412735316 posted

    You may also check the date fromat of ddl with db.

    Which event are you using to change selectcommand of sqldatasource it's very important. you need to do that before firing selecting event of sqldatasource or within that event. After that no changes in selectcommand will take effect.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 21, 2011 2:24 AM