Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,

I need help regarding filtering a date column in the gridview in Visual Studio 2010. This is my code:

Me.HVseznamBindingSource.Filter = "Date = #" & Me.Datetimepicker1.Value & "#" 

But, when I run this code the gridview returns 0 records.

I do not know what it could be. I have changed the date format on all fronts, table, DateTimePicker. Short, Long, custom. However, it still gives the same results, or getting code error that #" & Me.Datetimepicker1.Value & "#" is wrong format.

Would someone check this code or point me in the right direction on how to filter gridview by date.

Thank you in advance for your help to anyone!

[original title]
Filter gridview by datepicker??!! (Visual Studio)


Modification: (Moved from answer)

Thanks for your replies.
I have found the code:

VB
Me.HVseznamBindingSource.Filter = "Date = '" & Me.Datetimepicker1.Value.date & "'"


It can be used for Access or Sql server...
End Modification
Posted
Updated 24-Dec-10 11:37am
v4

1 solution

Do you use MS Access, Sql Server or what as a data source? In any case, I would try to:
(a) change date delimiter, use # delimiter for Access and single quote (') for Sql Server,
(b) change equal (=) operator with between operator (eg. filter = " between '2010/01/01 00:00' and '2010/12/31 23:59' ";),
(c) forget date time picker for a while and replace with hard coded dates to debug the problem,
(d) use standard database date time formats (yyyy/mm/dd hh:mm:ss) (eg. 2010/12/31 23:59).

I hope this helps,
Good luck.
 
Share this answer
 
Comments
Dalek Dave 23-Dec-10 20:11pm    
Good Call.
dmageiras 24-Dec-10 2:05am    
Thank you Dave.
Manfred Rudolf Bihy 24-Dec-10 17:30pm    
D'accord! 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900