I suggest changing your to something like the following to use the
DATEDIFF
SQL function. If the difference between the two days is zero, they are the same date.
... from logindata where DATEDIFF(day,logintime,CAST('" + textbox1.text + "' As SmallDateTime)=0;",con);
If you haven't done so already, you need to add some code to validate that
textbox1.text
contains a valid date. I usually use
CDATE()
within a
Try Catch
block to see if a date is a valid date.
That said, I
strongly suggest that you change your SQL
Select
statement to a parameterized query instead of using a concatenated string. Using a concatenated string, as you did, leaves you program vulnerable to an SQL Injection attack. Also, there is a performance benefit if you use parameterized queries. See this article
Use SQL Parameters to Overcome Ad Hoc Performance Issues[
^]