vb.net - How to use BindingSource.Filter for a Date in visual basic 2012? -


I am trying to filter my database which will show all the bookings for a date selected from a calendar on my form. I have this code written by me ...

  The response given as the date of public time in the form of an integer public sub filtering (selDate) '// here I On a selected date, a filter for Boeing will be made by the calendar dated date. In = selDate date date time as the head of date as time & amp; "00:00:01" Debt to = sealed & amp; "23:59:59" MSBBC (Datufom) MSBX (date to) m. Sequetting Infibeansource.filter = "bookingdate = gt; = #" & amp; From date & amp; "# And booking_date & lt; = #" & amp; Debt to End amp; GarageDataSet.queryBookingInfo 'table: "#" End Sub Private Sub frmMain_Load (as this object, e EventArgs as) MyBase.Load' handles code load data row TODO 'in. You can move, or remove it, as needed. Me.QueryBookingInfoTableAdapter.Fill (Me.GarageDataSet.queryBookingInfo) (selDate) End Sub following sub FilterBooking run 'set main calendar to selDate currently selected date variable selDate = mainCalender.SelectionStart.Date' in  

filter when debug this error message I made ...

type an unhandled exception verb 'System.FormatException' occurred in mscorlib.dll

Additional information: The string was not recognized as a valid date time.

Can anyone show me where im is making a mistake

PS I have also tried this filter << p>

  ME.UpicisingInfoBounding Source Filter = "bookingdate" = # "& amp; DateFrom.ToString ("dd / MM / yyyy hh: mm: ss") & amp; "# And booking_date & lt; = #" & amp; Date to Toastring ("DD / MM / YY HH: mm: SS") & amp;  
  

Have you tried to format your dates?

  Me.QueryBookingInfoBindingSource.Filter = "BookingDate> =" & amp; String.format ("# {0: yayam / mm / dd hh: mm: ss} #", datfom) & amp; "And the bookingdate is & lt; =" & amp; String.Format ("# {0: yyyy / MM / dd HH: mm: ss} #", dateTo)  

Edit:

IMHO it cleaner and easier to read:

  public sub FilterBooking (selDate) dim datetime as dateFrom = selDate.Date datetime = dateFrom as dim dateTo. AddDays (1) KSubtract (new time period (1)) dim filterBuilder new StringBuilder () string in as dim filterFormat = "BookingDate {0} # {1: yyyy / mM / yyyy HH: mm: ss} # "filterBuilder .AppendFormat (with filterFormat," & gt; = ", dateFrom) .Append (" aND ") .AppendFormat (filterFormat," & lt; = ", Me.QueryBookingInfoBindingSource.Filter = filterBuilder.ToStrin with dateTo) G end () End Sub  

It will be able to get the date with time values ​​without crashing, which will not pre-code;) That is being said, because SelDate has been declared outside of the law, you probably do not want to start with a parameter method.


Comments