locked
Trigger Event Name by Date RRS feed

  • Question

  • User1268451137 posted

     Novice skill level here, please be gentle.

    I've written this code to display a group of events when the value is 12/19/2010.  This means each day I need to change the "default value" to the current date to display the events of the day.  I would like to make this such that the change occurs automatically, that is, on 12/20/2010, I'd like to see just the events for 12/20/2010. 

    <asp:SqlDataSource ID="testeventdate" runat="server" ConnectionString="<%$ ConnectionStrings:testdateConnectionString %>" SelectCommand="SELECT [eventDate], [eventDesc] FROM [programEvents] WHERE ([eventDate] = @eventDate)">
      <SelectParameters>
       <asp:querystringparameter DefaultValue="12/19/2010" Name="eventDate" QueryStringField="eventDate" Type="DateTime" />
      </SelectParameters>
     </asp:SqlDataSource>

    Any advice would be much appreciated.


     

     

     

    Sunday, December 19, 2010 11:00 AM

Answers

  • User1268451137 posted

    I have no idea why this works but so far it seems to be OK.

    <asp:SqlDataSource ID="testeventdate" runat="server" ConnectionString="<%$ ConnectionStrings:testeventConnectionString %>" SelectCommand="SELECT [eventDate], [eventDesc] FROM [programEvents] WHERE ([eventDate] = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))) ORDER BY [eventDate], [startTime]">
     </asp:SqlDataSource>

    Something about the time at 12:00:00. Not sure why that is relevant since my event date is in a date column, not a datetime, but it seems to be working. 


     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 20, 2010 3:44 PM

All replies

  • User626880745 posted

    Yeah, you should be able to compare directly to whichever is your DateTime column using GetDate()

    like, 

    "...WHERE ......startTime = GetDate()"

    Sunday, December 19, 2010 7:33 PM
  • User1268451137 posted

    I added the GetDate() to my code.  The result is an empty grid, even though I have events for every day of the month.  I suspect part of the problem is the the "default value 12/19/2010" statement but I'm not sure what to do with that.   

    Monday, December 20, 2010 9:28 AM
  • User626880745 posted

    I added the GetDate() to my code. 
     

    show us what you did.


    Also, you don't need "[eventDate] = @eventDate" and the  QueryStringParameter 'EventDate' and you can remove the same.

    IF eventDate is the DateTime column, you needed to do this: WHERE ([eventDate] = GetDate())"

    Monday, December 20, 2010 10:04 AM
  • User1268451137 posted

    I have no idea why this works but so far it seems to be OK.

    <asp:SqlDataSource ID="testeventdate" runat="server" ConnectionString="<%$ ConnectionStrings:testeventConnectionString %>" SelectCommand="SELECT [eventDate], [eventDesc] FROM [programEvents] WHERE ([eventDate] = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))) ORDER BY [eventDate], [startTime]">
     </asp:SqlDataSource>

    Something about the time at 12:00:00. Not sure why that is relevant since my event date is in a date column, not a datetime, but it seems to be working. 


     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 20, 2010 3:44 PM