Pergunta

The UserLoginPerDay column in my database has a DateTime property. The idea is that I grab that column with some other columns and display it on my asp.net website in a grid view.

However I noticed while writing this statement that I have to input a time value else it will not show any records. I just want to be able to select a day in my calendar and every record that is equal to that day will show up, ignoring time.

I am using a SqlDataSource

ASPX page

<asp:Calendar ID="Calendar1" runat="server" 
    onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:LoginProject %>" 
    SelectCommand="SELECT UserLoginToday.UserId, Gebruikers.Lastname, Gebruikers.Firstname, UserLoginToday.UserLoginPerDay FROM Gebruikers INNER JOIN UserLoginToday ON Gebruikers.UserId = UserLoginToday.UserId WHERE (UserLoginToday.UserLoginPerDay = ISNULL(@datefilter, UserLoginToday.UserLoginPerDay))" CancelSelectOnNullParameter="false"><SelectParameters>
        <asp:ControlParameter ControlID="Calendar1" Name="datefilter" 
            PropertyName="SelectedDate" />
    </SelectParameters>
</asp:SqlDataSource>
Foi útil?

Solução

DateTime includes both date and time data. Unless all the rows in the database have a 0 as the time part and your application also sends 0 as the time part, they'll never be equal.

If your database is MS's SQL Server, I'd suggest you use the DATEDIFF function to compare dates.

DATEDIFF(DAY, date1, date2) = 0

is true if both dates are the same, ignoring the time part of the value.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top