我正試圖過濾我的數據庫,以顯示從日曆中選擇的所有日期,這些日期是在我的表單上顯示的。這是我寫的代碼...如何在Visual Basic 2012中使用BindingSource.Filter作爲日期?
Public selDate As DateTime
Dim response As Integer
Public Sub FilterBooking(selDate)
'// Here I will create a filter to for boookings on selected date from calender
Dim dateFrom As DateTime
Dim dateTo As DateTime
dateFrom = selDate & " 00:00:01"
dateTo = selDate & " 23:59:59"
MsgBox(dateFrom)
MsgBox(dateTo)
Me.QueryBookingInfoBindingSource.Filter = "BookingDate >= #" & dateFrom & "# AND BookingDate <= #" & dateTo & "#"
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'GarageDataSet.queryBookingInfo' table. You can move, or remove it, as needed.
Me.QueryBookingInfoTableAdapter.Fill(Me.GarageDataSet.queryBookingInfo)
'set currently selected date in the main calender to selDate variable
selDate = mainCalender.SelectionStart.Date
'run the following sub
FilterBooking(selDate)
End Sub
調試時,我創建了過濾器給出了這樣的錯誤消息...
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: String was not recognized as a valid DateTime.
有人能告訴我IM犯了一個錯誤。
PS我也試過這種過濾器=
Me.QueryBookingInfoBindingSource.Filter = "BookingDate >= #" & dateFrom.ToString("dd/MM/yyyy hh:mm:ss") & "# AND BookingDate <= #" & dateTo.ToString("dd/MM/yyyy hh:mm:ss") & "#"
你使用什麼樣的數據源? – Crono
本地存儲訪問數據庫 –
沒有我的意思是在調用代碼端。它是一個數據集?實體對象?波蘇斯? – Crono