Selecting rows from Access database by date search criteria in VB.NET form

前端 未结 1 485
渐次进展
渐次进展 2021-01-24 06:19

I have a very simple problem. I have a couple of datepicker controls on my VB.NET form and users select \"startDate\" and \"endDate\", and all rows from the related table are di

相关标签:
1条回答
  • 2021-01-24 06:49

    What could be the issue with this is the string format. I'm not sure if Access will convert the string to a Date and then compare or convert the Date to a string and then compare. You can try this:

    Format(Orders.OrderDate,'mm/dd/yyyy') >= Format(#" + startDate.Value.Date + "#,'mm/dd/yyyy')

    Or you could always just use the date directly,

    OrderDate >= #" + startDate.Value.Date + "#"

    Edit:, to do my due diligence, you really should be doing the query like this

    OrderDate >= @StartDate
    

    Then add this code

    adapter.Parameters.Add("@StartDate", startDate.Value.Date);
    

    Using parameters is important for robust code and to avoid the dreaded SQL injection attack.

    0 讨论(0)
提交回复
热议问题