I have a From and To
DateTimePicker. I converted them into a
String and use it to filter a
MsAccess database of a specific range but there is a problem with the filtering. For example, I would like to filter from January 1, 2015 to January 31, 2015. The results include Januaries from previous years. What seems to be the problem with my statement?
This is my code:
Dim connectionstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\STSlog.mdb;Jet OLEDB:Database Password=password;" Dim conn As New OleDbConnection(connectionstring) Dim command As New OleDbCommand Dim commstring As String Dim fromdatestring As String = FromDPicker.Value.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture) Dim todatestring As String = ToDPicker.Value.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture) commstring = "SELECT Mark, ProjectCode, Project, Activity, today, Regular, OT FROM data WHERE today BETWEEN '" & fromdatestring & "' AND '" & todatestring & "' AND empno = '" & TimeSheetAdmin.EmpNumCmbBox.SelectedItem.ToString & "' ORDER BY VAL(Mark) DESC" command = New OleDbCommand(commstring, conn)